[Tips & Tricks] Determine length of a string

[Tips & Tricks] Determine length of a string

There was a requirement from a user to define the minimum and maximum string (value) length a user can put into an additional field. The requirement is that when a user puts in a value lesser than the minimum length and greater than the maximum length defined in the script, the submission should be stopped followed by an alert message. This was achieved using a Java Script through Field and Form Rules.

We thought this could be useful to others in various scenarios. Hence, posting it here. 


var field =  $CS.getValue("WorkOrder_Fields_UDF_CHAR33"); 
var mnlen = 8;
var mxlen = 30;
if(field.length<mnlen || field.length> mxlen)

alert("Please ensure the value has the length between " +mnlen+ " and " +mxlen+ " characters");
  $CS.stopFormSubmission();


Here are the steps to configure the same:

Go to Admin > Incident Management > FIeld and Form rules. Add a new rule under "Form Submit Event" and add the below script under Execute script. Find the field name and update it in the script and set the minimum length (mnlen) and maximum length (mxlen) as per your requirement.

 To find the field name, click on the field listed on the left pane, you would see the name as in the screenshot below.



                New to ADManager Plus?

                  New to ADSelfService Plus?