The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Set Minimum Character Limit

Dan Tolgyesi1
Tera Expert

Hi,

I was just wandering if anyone knows how to set a minimum character limit on a string field. I know you can set a maximum length limit using the system dictionary .

This is to prevent users from puting just a "." or a space in the field etc.

Any help is appreciated.

Thanks
Dan

8 REPLIES 8

Thanks for your help. What I struggle with though is to get the script to check the characters in the field before hitting the Update button. It gives you the message too short as soon as u_local_job is true is met. This is my current script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
if(g_form.getValue('u_local_job') == 'true' ){
g_form.setMandatory('work_notes' ,true);
g_form.showFieldMsg('u_local_job','Please enter a reason why in work notes', 'error');
var myFieldValue = g_form.getValue('work_notes');
if (myFieldValue.toString().length < 3) {
g_form.setValue('work_notes','');{
alert('Please enter 3 or more characters.');
}
}
}
else{
g_form.hideFieldMsg('u_local_job','Please enter a reason why in work notes', 'error');
g_form.setMandatory('work_notes', false);
}
}

Can you help or is this too specific to our environment? Thanks.

Alex


This was only a year ago , but did you find a solution for this Alex?


Geoff. It's old question     but I'm new in scripting and for my works perfectly!   (After more than one year!)


Thank you very much!


Mike Malcangio
ServiceNow Employee
ServiceNow Employee

I know that you're after the technical answer to this question, but I would like to throw out there that in past lives putting a minimum # of characters resulted in a strange Parkinson's Law like phenomena of people expanding the number of gibberish characters necessary to fill that space. We found that we were better off by being very very diligent about when and where we used mandatory fields (people had to argue very hard for us to make a field mandatory) and if it was mandatory making it evident what the WIFM was for them and how it affected a downstream process.




One interesting thing that could be done with ServiceNow these days is to leverage Coaching Loops so that you assess folks on how well they're doing these kind of activities and then coach them on the process, WIFM, and overall importance of why it's a good idea to provide solid and complete closure notes.