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

Hi, I want to add this check to one variables on a record producer. Do I add this to the the record producer table? Apologies, I am not familiar with scripting - help is greatly appreciated.


You have to write a catalog client script. I m not in front of system currently.


I can share more details with scrrenshots If you are stil blocked



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


Hi, I have used a catalogue client script but I am getting an error on variable name. Please see below screenshots.



Kind regards,


Emma


You have to select the type as onSubmit in the client script and then paste the script I have shared between the onsubmit functions.


Alternatively if you want this to be part of onchnabe then select the type as on change and follow the same process


find_real_file.png



I am still getting an error I'm afraid. The error is referring to the variable name. Do I need to change this? 'salary' is the variable name which is part of the variable set outlined in the screenshot.



Thanks,


Emma