- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 12:30 AM
We are having an integer type field in a table, and we want to restrict that field to not enter the decimal values.
We have tried a client script for the string type field but unable to do for integer type field.
Can anyone help?
Please find the attachment of the field type info.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 01:37 AM
Hi @Pavan S,
I'm a little confused here. With a field type of 'Integer', ServiceNow will not allow decimals or string characters to be saved within this field. My only assumption here is that you would like to validate at the time of entering with the use of a Client Script - see below for an example.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = /^[0-9]+$/;
if(!regex.test(newValue)) {
g_form.clearValue('u_test_integer'); //adjust the field name appropriately
g_form.setValue('u_test_integer','');
g_form.showFieldMsg('u_test_integer', 'Only integer numbers allowed. Decimals not permitted', 'error');
g_form.showFieldMsg()
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 01:26 AM
OOB the UI will display a warning to a user if they try to submit a form whereby the value in an integer field is invalid. Are you wanting to show a similar error message earlier (e.g onChange?). Are you finding the OOB solution delivered by SN insufficient, or is this a training issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 02:18 AM
Hi Kieran,
yes, we have tried the below on change client script but it didn't worked.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var regex = /^[0-9]*$/;
if (!regex.test(newValue)) {
g_form.setValue('u_full_name', ''); //full name is the backend name of Number
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 02:33 AM
Hi @Pavan S,
This was actually the script I provided. I've tried and tested it on my PDI. I can only assume something is misconfigured, let me provide some screenshots to help you.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 01:37 AM
Hi @Pavan S,
I'm a little confused here. With a field type of 'Integer', ServiceNow will not allow decimals or string characters to be saved within this field. My only assumption here is that you would like to validate at the time of entering with the use of a Client Script - see below for an example.
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = /^[0-9]+$/;
if(!regex.test(newValue)) {
g_form.clearValue('u_test_integer'); //adjust the field name appropriately
g_form.setValue('u_test_integer','');
g_form.showFieldMsg('u_test_integer', 'Only integer numbers allowed. Decimals not permitted', 'error');
g_form.showFieldMsg()
}
}