How to restrict variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 08:52 AM
Hello team , how do i restrict multiline variable with 10words in catalog item ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 08:54 AM
Hello,
You can use Regex to accomplish this on the MVRS, such as here: https://www.servicenow.com/community/developer-forum/how-do-i-restrict-length-of-characters-of-varia... -- but this is for character count, but the same can be done for words, such as: https://stackoverflow.com/questions/557695/limit-the-number-of-words-in-a-response-with-a-regular-ex...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 08:59 AM
On Change client script. You will need to something like this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var text = newValue.toString().Split(" ");//sprit sting into an array by space between words
if (text.length > 10){//Check length of array is greater then 10
alert("No more then 10 words can be in filed");
g_form.clearValue("variable name");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2024 09:44 AM
Hi @pramn ,
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } alert('Testing...'); //Type appropriate comment here, and begin script below var charLimit = 250; var reasonForNomination = g_form.getValue('reason_for_nomination'); if (reasonForNomination.length > charLimit){ g_form.setValue('reason_for_nomination', reasonForNomination.substring(0, charLimit)); g_form.addFieldMessage('reason_for_nomination', 'Maximum character limit exceeded. Please limit your input to ' + charLimit + ' characters.'); return false; }else{ g_form.clearMessages(); return true; } }
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Thanks & Regards,
Sumanth Meda