how can sum of two variables and populate in third one on catalog form?

Chandra18
Mega Sage

Hi team,

 

There are three fields total amount, P.Amount, and L.Amount. here total amount = P.Amount + L.Amount.

All fields accept number values on the catalog form, I want if the value gets a change of any variables (P.Amount + L.Amount) the total amount value should be changed.
How can I achieve this?
Thanks

6 REPLIES 6

Sagar Pagar
Tera Patron

Hi,

 

You can try it using on-change Catalog client scripts.

 

Sample scripts -

var value1 = newValue;
var value2 = g_form.getValue("variable_2");

var sum = parseInt(value1) + parseInt(value2);
alert("sum: " + sum);

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hello @Sagar Pagar ,

Type is on-change but there there are 2 fields (P.Amount + L.Amount) which field needs to select in the client script?

 

 

Hi,

Select 2nd field for on-change and try updated scripts.

 

 

var value1 = g_form.getValue("variable_1");
var value2 = newValue;

var sum = parseInt(value1) + parseInt(value2);
alert("sum: " + sum);

 

 

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Hello @Sagar Pagar ,

Chandra18_0-1665508792945.png

As per the attached screenshot, "9" should be auto-populate in "Total amount"