Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Value entered in first variable needs to be multiply by 36 and populate in second variable

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, in catalog form there are 2 variables (see screenshot)

suuriyas_0-1755603289661.png

whenever the value entered in Expected Yearly Mileage (km) - Total then that value needs to multiply by 36 and populate in Estimated mileage Km per 36 months

For example; if i enter 11 in first variable then 396 (36 x 11) needs to be populate in second variable how can we achieve this

Please help me with the onchange client script 

1 ACCEPTED SOLUTION

There was an error in the script try below:

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

 

   var mil = parseInt(newValue);
   g_form.setValue( 'estimated_mileage', mil*36);
   
}

Raghav
MVP 2023
LinkedIn

View solution in original post

8 REPLIES 8

RaghavSh
Mega Patron

Write an on change client scripts on expected milage field:

 

var mil = parseInt(g_form.getValue(newValue));

 

g_form.setValue(‘yearly_var_name’, mil*36);


Raghav
MVP 2023
LinkedIn

HI @RaghavSh ,

 

Thanks for the response,

 

I have written like this but it did not work

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var mil = parseInt(g_form.getValue(newValue));
   g_form.setValue( 'estimated_mileage', mil*36);
   
}

Can you please let me know what mistake i have done

It populates but showing as empty

suuriyas_0-1755605759394.png

 

There was an error in the script try below:

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

 

   var mil = parseInt(newValue);
   g_form.setValue( 'estimated_mileage', mil*36);
   
}

Raghav
MVP 2023
LinkedIn

Hi @suuriyas ,

 

Can you please share complete screenshot of the script where i can see Table and on which fiedl change you are doing it?

 

regards,

Nikhil Bajaj

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

ServiceNow Rising Star-2025