Setting the Maximum Length for a String Variable
Here's a UI Script you can use in the Service Catalog to set the maximum length of a string variable to limit how many characters a user can enter:
Name: u_setMaxLengthDescription: Function to set the "maxlength" attribute on an input fieldActive: CheckedGlobal: CheckedScript:function u_setMaxLength(variableName, size) { try{ var fieldName = g_form.getControl(variableName).name.toString(); if (Prototype.Browser.IE) { fieldName.placeholder = size; } else { $(fieldName).writeAttribute('maxlength', size); } } catch(err) {}}
You can then call it from an onLoad client script:
function onLoad() { u_setMaxLength("test123", 5);
}
And now users are limited to just 5 characters for that variable.
It can actually be used in normal forms as well, but probably more useful with Catalog Variables as you cannot define their lengths. Attached is the UI Script XML file for import into your instance.
https://www.servicenow.com/community/in-other-news/setting-the-maximum-length-for-a-string-variable/ba-p/2274751