Setting Max length for a string field based on choice selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2013 12:29 PM
Hi -
I have a field in Service now that I need to limit the max length based on a selection from a drop-down list.
The field in question is a string field and I have been able to set the current max length to 25 characters, but I need this to be set to 11 characters based on 1 entry in my drop-down selection list.
Any assistance will be very much appreciated.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2013 01:02 PM
Maybe try an onChange client script on the drop-down field, and if it has that one value, do this (replace "short_description" with your field name):
var e = g_form.getControl("short_description");
if (e)
e.setAttribute("maxlength", 11);
If it has another value, set maxlength to 25.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2013 07:08 AM
Hi -
I have tried your sample script and i still can't force the field limited to 11 characters when a particular selection is mode from my drop-down list. Below is what I currently have for my script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var sap = g_form.getControl("u_job_type");
if (sap == "SAP Job"){
sap.setAttribute("maxlength", 11);
}
}
Am i missing anything else?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2013 03:41 PM
Hi.
What you currently have doesn't work: if (sap == "SAP Job")...
You should also declare another variable for your choice field. This is an onChange Client script for the field that contains your choices.
Try this:
function onChange(control, oldValue, newValue, isLoading) {
var ujt = g_form.getControl('u_job_type');
var ichose = g_form.getValue('choicelist'); //replace with the your field name
if (ichose == 'SAP Job'){
ujt.maxLength = 11;
}else{
ujt.maxLength = 25;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2013 08:18 AM
I have tried your sample script and it's still not working for me. I was also thinking of another way to get this done - checking the length of a field to make sure it fits the max length requiremnt of 32 characters but I am not sure how to check that.
Any assistance will be very much appreciated.
Thanks.