Script include for record producer variable length

Joe Weisiger
Giga Expert

Hello,

I have multiple similiar record producers that all require a common variable 'Description' to be a minimal of 251 characters.  I also need to validate that 'Description' is not the same as 'Short Description'.

I wrote an onChange catalog client script on the description field that works for this, but I want to see if it would be smarter to create a script include with the logic for length so that it can be shared across all required forms to pass in the length so it can be dynamic as a parameter.

How would I go about creating the script include and how should I call it in the record producer?

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 short_desc = g_form.getValue('description');
       if(short_desc.length < 251){


                  alert("Please enter a description longer than 250 characters.");

        }

}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

AnirudhKumar
Mega Sage
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
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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I ended up creating a variable set with the 2 variables and catalog client script and it works well.  Thank you for the help!