How to calculate Total in MRVS when users enter values in any order?

Ankit Balapure
Tera Contributor

Hi everyone,

I'm working on a Multi-Row Variable Set (MRVS) in a catalog item and need help with calculating a Total field based on the values entered in multiple fee fields.

 

Use Case

I have the following fields in my MRVS:

  • transportation_fee

  • accomodation_fee

  • meal_fee

  • other_fee

  • total (read-only)

Users can enter values in any order in any of the fields above (some fields may even be left blank). Once all the fee fields have values (or at least the fields that are filled), the Total field should automatically update with the sum.

AnkitBalapure_0-1750156063093.png

 

 

What I Tried

  • I created a Catalog Client Script of type onChange and set Variable name = None, but it did not get triggered.

  • I don’t want to create 50 onChange scripts if I have 50 fields.

  • I want a single script that can listen to changes in all fee fields and calculate the total.

AnkitBalapure_2-1750156224794.png

 

What I Want

  • A single client script that can watch all specific fields in MRVS.

  • It should update the Total field automatically when any fee field is changed.

 

 

 

Can someone help me with:

  • The best approach to achieve this efficiently?

  • Any sample script or working example?

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankit Balapure 

you can use onSubmit catalog client script which applies on MRVS and then get all the values and sum and then set (I haven't tested this)

OR

single field cannot watch

you can check this link and see how it's detecting row is added/removed

so whenever row is added, simply sum and try setting the value

Widget that reacts to onChange event of Variable 

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

@Ankit Balapure 

Hope you are doing good.

Did my reply answer your question?

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

Ankit Balapure
Tera Contributor

Hi @Ankur Bawiskar,

 

I have tried it with the onSubmit() but it is not working. It is not setting the value to any of the variables in the MRVS. It will be very helpful if you tell me how to write the onSubmit client script in the MRVS itself to set the value to its own variable.

 

Thanks,

Ankit

@Ankit Balapure 

I tried that yesterday and found it doesn't work.

did you check the link I shared which talks about detecting when row is added/removed

Widget that reacts to onChange event of Variable 

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