- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 03:35 AM
Hi,
I am currently working on a HR on-boarding solution - one of the requirements is to have a script on a variable to check that the salary figure is divisible by 3.
Is anyone aware of a way to do this?
Thanks in anticipation!
Emma
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 07:52 AM
HI Emma,
I've reproduced this on demo instance below. Please refer this for reference.
https://demo007.service-now.com/login.do
Username : admin
Password : admin
Record producer : Create incident.
Here is the final script with screenshots too.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Replace u_short with the column name of your variable.
var sal = newValue%3;
if(sal != 0)
{
alert('should be divisible by 3');
g_form.setValue('salary',''); //Replace salary with the name of the variable you have created
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 03:39 AM
Hi Emma,
This seems to be straight forward.Are you facing any issues while doing so?
You can use Modulus operator. i.e variableValue%3==0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 03:41 AM
Here you go.
var short = g_form.getValue('u_short'); //Replace u_short with the column name of your variable.
var short = short%3;
if(short == 0)
{
alert('divisible by 3');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 06:04 AM
Hi, thank you for your reply. Do I add this as a client script? Which table should I add this on please?
Kind regards,
Emma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2015 06:20 AM
Yes you are correct.
Add this as a client script on the table where you have this field on the form.