Cris P
Tera Guru

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
	});
   
}

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
		});
 
}

I tried this with the onLoad script and cannot get it to work.  I get a javascript error when the record producer loads

AnirudhKumar
Mega Sage

Have you considered using a variable set for this?

The variable set would only contain a single field - Description, and the client script.

Ankur Bawiskar
Tera Patron

Hi,

you want to validate this on catalog/record producer form right?

Also I assume both description and short description are variables on that record producer.

Why not add those 2 variables as part of single variable set and create catalog client script which applies on variable set?

You can add this variable set to all your catalog items and the script will work on every form

Regards
Ankur

View solution in original post