
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2022 08:44 AM
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.");
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 07:38 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2022 07:38 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2022 01:27 PM
I ended up creating a variable set with the 2 variables and catalog client script and it works well. Thank you for the help!