Restrict additional comments field to accept only 4000 characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 06:03 AM
Hi Team,
The requirement is to restrict the additional comments(Journal Input - field type) field to accept only 4000 characters on case record. Can anyone please help me how to achieve this requirement. Thanks in advance. I have written onChange client script on case table,
Script: //testing purpose I'm trying to restrict 4 characters only
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var v_comments = g_form.getValue('comments');
var count = v_comments.length;
if (count > 5) {
alert("No.of characters " + count);
g_form.setValue('comments', v_comments.substring(0, 4));
}
}
still it is allowing to enter 5th character but the requirement is to stop allowing the 5th character.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 06:39 AM
@Pandu3 During the edit, additional characters would still be allowed, however, the moments user moves away from the comments field, the onChange script on comments field would trigger and reset the characters to 5 characters.
Even if you define max length at the field level, the extra characters in the field would still be allowed. This behavior is already documented here https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0750494
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 12:42 AM
Hi All,
I am getting results as if the user continuously enters characters after 4 characters, then it is showing alert after entering 6th character and restricting & displaying 4 characters in comments field. But if user clicks on "Enter" button after entering 4 characters, then it is considering the new line characters too in the comments. Please help me how to restrict it. Thanks in advance!
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var v_comments = g_form.getValue('comments');
var v_count = v_comments.length;
if (v_count > 5) {
alert("Maximum characters reached " + v_count);
alert("Entered substirng value " + v_comments.substring(0, 4));
g_form.setValue('comments', v_comments.substring(0, 4));
}
}