Field Validation in Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2017 10:38 PM
Hello,
I want to have field level validation in Record Producer
for e.g.,
My short description field will only take 80 character,
When it exceeding above that 80 character,it should not allow it.
Below code will work in CMS, but in Service Portal it won't work as 'getcontol' methodn won't support it mobile.
Can some one give an input on this?
function onLoad() {
//Use the 'onkeyup' event to check the 'isMaxLength' function
//Get the control
var control = g_form.getControl('short_description');
alert(control); //Set its onkeyup method
control.onkeyup = isMaxLength;
}
function isMaxLength(){
var mLength=85;
var control = g_form.getControl('short_description');
alert(control);
if (control.value.length > mLength){
g_form.hideErrorBox('short_description');
g_form.showErrorBox('short_description', 'You have reached the maximum character limit for this field.');
control.value=control.value.substring(0,mLength);
}
else{
g_form.hideErrorBox('short_description');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2017 10:57 PM
Hi
you can just add the max_length = 80 parameter to the Variables attributes field
Variable Types - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2017 11:23 PM
Hello Lars,
Thanks.It was very helpful.
I have wrote an client script on change of short_description. I want to show an message to user to know they have reached the limit
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue.length>80)
{
g_form.addErrorMessage('You have reached the limit');
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2017 11:24 PM
The above code is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2017 11:37 PM
Hi you have applied the max_length attribute you will not get above the limit. The code should be
if(newValue.length == 80)
{
g_form.addErrorMessage('You have reached the limit');
}