Script on variable to ensure figure is divisible by 3

ebaileyybs
Tera Expert

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

1 ACCEPTED SOLUTION

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



}


Screen Shot 2015-09-07 at 8.21.56 PM.JPG


View solution in original post

16 REPLIES 16

Looks correct. You should throw the alert if the value is not equal to 0..also on client script select the checkbox where you want this script to be applied.


Coming to error part..blank the complete script and then past line by line and check once



Sent by Outlook<http://taps.io/outlookmobile> for Android


Hi, I have selected the checkbox and pasted the script but I still get the variable name error. Is there anything else I could try?



Kind regards,


Emma


Hi, I have replaced 'u_short' with the variables name 'salary' but I am getting an error. Please see below:



find_real_file.png


Full screenshot



find_real_file.png


hi,



just see, variable which are using here is already declared in record producer or not!



thanks


Amit