- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 05:08 AM
Hello,
Farley new to developing in ServiceNow, but I am tasked with creating a numeric input field that can only contain a value that is a multiple of the number 8; example would be, 8, 16, 24, 32,40…….
I know this would be a UI action, but how can I code to validate the input?
Thanks in advance for your guidance.
Solved! Go to Solution.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 05:39 AM
Hi Rick,
You should validate this via OnChange Client Script. Please refer below code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue % 8 != 0) { // If the value is not multiple of the number 8;
alert("PASS ALERT MESSAGE HERE");
g_form.clearValue('PASS FIELD COLUMN NAME HERE');
}
//Type appropriate comment here, and begin script below
}
-Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 05:39 AM
Hi Rick,
You should validate this via OnChange Client Script. Please refer below code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue % 8 != 0) { // If the value is not multiple of the number 8;
alert("PASS ALERT MESSAGE HERE");
g_form.clearValue('PASS FIELD COLUMN NAME HERE');
}
//Type appropriate comment here, and begin script below
}
-Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 05:53 AM
Hi Rick,
1) You need to create the 'Onchange' client script, as below. in the field name below select your Field name.
Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue % 8 == 0){
return true;
}
else{
g_form.showErrorBox('u_integer','please add only multiple of 8',false);
return false;
}
}
Please Mark it correct/helpful, if it helps you.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2020 07:05 AM
Hi,
You can follow the below steps:-
Step 1:- Create an onChange client script for the field to validate it.
Script:-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue % 8 == 0){
return true
}
else{
g_form.clearValue('<Integer field name>');
g_form.showErrorBox('<Integer filed name>','please add only multiple of 8',false);
return false;
}
}
If i was able to solve your query, please mark my answer correct and helpful.
Thanks & Regards
Prasant kumar sahu