Regarding on change client script

SNOW24
Tera Contributor

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.

3 REPLIES 3

Anup Desai1
Mega Sage

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

 

 

Rahul Talreja
Mega Sage
Mega Sage

@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');


       }


}

 

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Ankur Bawiskar
Tera Patron
Tera Patron

@SNOW24 

it should be simple enough.

what script did you start with and where are you stuck?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader