Integer validation

Daniel Voutt
Tera Contributor

Hi,

I want to add a simple validation to a custom integer field.  I can see how the validation scripts work, and that there is a script to do exactly what I need, however, I cannot see how I can link the validation script to the custom field.

The field is called u_minutes and is within the incident table.

Any guidance that could be provided would be greatly appreciated.

Thanks in advance,

 

Dan

1 ACCEPTED SOLUTION

Hmm.. I never thought about it, but it doesn't seem to be the validation script that turns it into a 0, it must be something else. But is it possible that the value never should be 0? then you should able to do a onChange for that field like this:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
     if (isLoading || newValue == '') {
           return;
     }
 if (newValue == 0){
	 g_form.showErrorBox('u_nummer','Please fill in a correct number');
 }
}

View solution in original post

8 REPLIES 8

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Dan,

Not sure I understand this. You don't define the field on validation scripts. You define which type of field the script should validate and then it will be instance wide. And for the integer type, there already is a baseline one. Perhaps it's more of a client script validation you are looking for?

//Göran

Feel free to connect with me:
 

Hi, 

 

Thanks for taking the time to reply - I have created a new field in the incident table which is an integer, at the moment if you put a text value in it it will just revert to a "0" when you save the record, so I want to add a validation step in the process to warn users that it wasn't a valid entry and to enter a numerical value instead.

I can see there is already a "integer" validation script OOTB, so I need to know how I can call that script and link it to my custom field, or alternatively, a more suitable way of achieving what I require.

Hopefully I have explained my requirements more clearly this time.

Thanks,

 

Dan

Hi 

 

Write a client script on submit check the value and send a notification 

Or you can write a business rule is well

 

Regards

Ravindra

Hi ,

 

You can use RegEx expression. Please write a onChange client script with below code.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue == '') {
          return;
    }

var regexp = /^[0-9].*$/;

if(!regexp.test(newValue))

 {

 alert('Only numbers and dot allowed');

 g_form.setValue('u_fieldname','');// Set Field Value

}

 

Thanks,

Bhojraj