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

View solution in original post

8 REPLIES 8

Nikhil Bajaj9
Tera Sage

Hi @suuriyas ,

 

Please write a client script - getvalue of first variable and Set it in secodn variable like -  First variable value * 36. Use setvaleu and getvalue, try to write code and in case any issue, ask us.

 

If my answer helepd you, please mark it- solution accepted.

 

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

HI @Nikhil Bajaj9 ,

 

Thanks for replying

 

I tried this 

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

   var mil = parseInt(g_form.getValue(newValue));
   g_form.setValue( 'estimated_mileage', mil*36);
   
}
but it did not work 

Hi @suuriyas ,

 

If you are using getValue then use - First variable name in quotes. ex:- parseInt(g_form.getValue('u_a'));

Else use newValue firectly without getValue.

parseInt(newValue);

 

If my answer helped you, please mark it- solution accepted.

 

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

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

it's an easy requirement and what did you start with?

Unless you start you won't learn.

You should write onChange catalog client script on 1st variable and ensure UI Type - ALL

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

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader