- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 10:52 AM
You can do this using UI script Checkout this article for detailed steps:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 11:20 AM
Hi there,
Here is a Script Include which returns true/false based on your specs (make sure 'Client Callable' is ticked on the same):
var CPcheckDescriptionLength = Class.create();
CPcheckDescriptionLength.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isLengthSatisified: function(){
// We can store the value 251 in a system property, or can just set it statically here:
var minimum = gs.getProperty('STORE_THE_VALUE_IN_PROPERTY') || 251;
// Check if our short desc is less than minimum, return true/false
return this.getParameter('sysparm_sd') < minimum;
},
type: 'CPcheckDescriptionLength'
});
Then from your client script call it like this:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('CPcheckDescriptionLength'); // The name of the Script Include
ga.addParam('sysparm_name', 'isLengthSatisified'); // The name of the method we want to use in the SI
ga.addParam('sysparm_sd', g_form.getValue('short_description')); // Pass your short description to the param we define in the SI
ga.getXMLAnswer(function(response){ // Callback function to use the 'response' from our SI
jslog(response); // Will be true or false
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 12:49 PM
Thanks Cris! I am trying to use this in the onChange script that I created to compare the short description and description. I am getting a javascript error on the portal record producer though.
Here is the onChange client script. Also, how to I add an alert popup if the description is under 251 characters?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Verify that Short Description and Description are not the same
var title = g_form.getValue('short_description');
if(title == newValue)
{
alert('Description cannot be the same as the short description. Please enter additional information.');
g_form.clearValue('description');
}
//Verify that Description is at least 250 characters
var ga = new GlideAjax('CPcheckDescriptionLength'); //The name of the Script Include
ga.addParam('sysparm_name', 'isLengthSatisified'); //The name of the method we want to use in the SI
ga.addParam('sysparm_sd', g_form.getValue('description')); //Pass your description to the param we define in the SI
ga.getXMLAnswer(function(response){ //Callback function to use the 'response' from our SI
jslog(response); //Will be true or false
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2022 07:12 AM
I tried this with the onLoad script and cannot get it to work. I get a javascript error when the record producer loads
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 11:43 AM
Have you considered using a variable set for this?
The variable set would only contain a single field - Description, and the client script.