How to make a single line text variable in service catalog to accept only numerical values

andrewdevadhas
Kilo Contributor

Hi SNOW users,

I have a Service catalog form with a single line text variable. I need to make it to accept only numerical values. 

Is there any similar validation properties available for any of the variables in service catalog

1 ACCEPTED SOLUTION

Pothuraju
Mega Expert

HI Andrew,

Have a look.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var number = g_form.getIntValue('u_quantity');
//if "Not a Number", clear the number value
if (isNaN(number)){
//number = "";
g_form.setValue('u_quantity','');
g_form.showFieldMsg('u_quantity','Please enter a valid integer number - stripping out non-numeric characters','info');

}

}

View solution in original post

6 REPLIES 6

HarshTimes
Tera Guru

HI Andrew

There is no numeric type available for variables. Yo can write a client script to enforce numeric value to the required field.Check below script

var var_name= g_form.getValue('VARIABLE_NAME');
var a = var_name.match(/^[0-9]+$/);
if(a == null){
g_form.clearValue('VARIABLE_NAME');
g_form.showFieldMsg('VARIABLE_NAME','this field should be numeric value only','error');

}

Pothuraju
Mega Expert

HI Andrew,

Have a look.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var number = g_form.getIntValue('u_quantity');
//if "Not a Number", clear the number value
if (isNaN(number)){
//number = "";
g_form.setValue('u_quantity','');
g_form.showFieldMsg('u_quantity','Please enter a valid integer number - stripping out non-numeric characters','info');

}

}

andrewdevadhas
Kilo Contributor

Hi Raju,

But this validation will hapen only after the order is submitted right? we can't do any validations prior that?

-Andrew

Andrew,

This client script is on Onchange condition. when ever variable value is changed- script will trigger to work.