Getting the Sum of all values from an MRV

Peter Williams
Kilo Sage

Hello everyone

what i am trying to figure out is how to get the Sum total of all values entered in a MRV to be async on the form before submitting.

I am created an expense form for employees to fill out and would like to have their totals to be disabled before they submit their form. 

I was able to figure out how to get the totals after submitted the form by added a Script on the Record Producer to total up all values:

find_real_file.png

 

However i am not able to make this work in a BR which i believe is the best way to do it.

This is a very basic screen but you will get the idea 

find_real_file.png

Here what i have so far in my Business Rule but this is coming from another posting i saw:

find_real_file.png

 

find_real_file.png

 

My table for the Recorder Producer is called:

u_tester

Variables are:

u_name

u_total

 

MRV internal name is:

test

Variable inside of the MRV is:

amount

18 REPLIES 18

So you dropped the idea of doing this before submitting, and are going for doing this after submitting. Correct?

Can you explain what you already debugged on the script. You are only mentioning id doesn't seem to work.
So what's not working?
Did you debug if the encoded query is valid?
Did you debug if the if condition is entered?
Or is the Business Rule not triggered at all?
Or debugged th contents of totalInt?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

sachin_namjoshi
Kilo Patron
Kilo Patron

Use can use below onsubmit client script sample to calculate sum of MVRS

Update MVRS variable name in this client script

function onSubmit() {
	
	var totalEstimatedAmount = parseFloat(g_form.getValue('total_estimated_amount_sgd'));
	var jsonStr = g_form.getValue("book_details");
	var objList = JSON.parse(jsonStr);
	var calculatedAmount = 0;
	for (var i = 0; i < objList.length; i++) {
		
		calculatedAmount += parseFloat(objList[i].estimated_price_sgd);
		
	}
	calculatedAmount = calculatedAmount.toFixed(2);
	

}

 

Regards,

Sachin

This is not what i would need. i was able to figure out how to get the totals after submitting the form but looking for the totals on the request form

i tried the client script but is not able to get it to work

find_real_file.png

find_real_file.png

rahulpandey
Kilo Sage

Hi,

Please replace line number 2 with below

grMRVSAnswer = new GlideRecord("sc_multi_row_question_answer");