Regarding on change client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2023 11:42 PM
in incident form i've one field i.e additional details if the user is trying to enter more than
the 100 characters then i need to show the pop message for that could you provide suitable script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2023 11:52 PM - edited ‎07-23-2023 11:56 PM
Hi @SNOW24 ,
Please add this script in onChange function and make sure to add correct name for that field.
var additionalDetailsField = g_form.getValue('additional_details');
// Check if the field has more than 100 characters
if (additionalDetailsField.length > 100) {
// Show the pop-up message
alert('Additional Details cannot exceed 100 characters.');
// Truncate the value to 100 characters
var truncatedValue = additionalDetailsField.substring(0, 100);
g_form.setValue('additional_details', truncatedValue);
}
Please mark the answer correct/helpful based on Impact.
Regards, Anup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2023 11:53 PM - edited ‎07-23-2023 11:53 PM
@SNOW24 ,
Try this, in onchange client script
var variablename = 'variable name here';
var mylist = g_form.getValue(variablename);
var maxitem = 100;
if (mylist.length>maxitem){
g_form.showFieldMsg(variablename,'Only 100 characters can be entered','error');
}
}
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2023 11:56 PM
it should be simple enough.
what script did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader