How to terminate the string characters in service now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 08:39 AM
Hi Team,
we trying to restricting the use for 20 characters for note field ,So we written client script onChange .we need to stop typing after 20 character and show an alert .but user enter more than 20 characters also ,Script not showing any alert
Below Is my code :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
var dec = g_form.getValue('notes');
// Calculate the byte length of the string using TextEncoder
var byteLength = new TextEncoder().encode(dec).length;
if (byteLength > 20) {
alert("notes length exceeds 4000 bytes');
return false;
}}
Please guide me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:21 AM
Hi @String,
Try below script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var dec = g_form.getValue('notes');
var charLength = dec.length;
if (charLength > 20) {
alert("Note length exceeds 20 characters");
g_form.setValue('notes', dec.substring(0, 20));
}
}
Mark it helpful and solution proposed if it serves your purpose.
Thankse,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:35 AM
Hi @Anand Kumar P thanks for your quick reply ,Is there any way to show alert immediately after exceeding 20 character while user entering the characters in notes field .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 11:19 PM
Hi @String ,
You can use
g_form.addInfoMessage("myObj");
or
g_form.showFieldMsg('<variable_name>', 'msg', 'info', false);
Mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand