Field Validations for a form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2016 12:56 PM
I have a field validation for field named " K-form " MANDATORY (Must be 11 character). I have written an onchange client script for this. Error Message is showing up, but Form is being saved even if 11 character condition is not met.
As, you can see in the below picture, field is turned green and saved. I want to restrict the form submission if condition is not met.
Please Help.
The code I have written for this is ,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.hideFieldMsg('u_k_form', true);
if(validate(newValue) == true)
{
return true;
}
else{
return false;
}
function validate(user_input)
{
var msg = 'Must be a valid 11 characters K-Form';
if (user_input.length==11)
{
return true;
}
g_form.showFieldMsg('u_k_form', msg, 'error');
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2016 01:00 PM
Here's a page sncguru did on the subject: Stopping Record Submission - ServiceNow Guru

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2016 10:30 AM
Hi Sai,
I worked on something similar only I took it a step further and forced the user to re-enter the value if they did not meet the requirements. I simply cleared the whatever they entered if it wasn't the right amount of characters. So after the line of code for the error message I inserted g_form.setValue('field_name_here', '')
Basically resetting the field.