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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Unfortunately, you cannot calculate the variable outside of the MRVS while adding rows in the MRVS. (or you would need to do this onSubmit or after submitting through for example Business rule).

What might be an alternative, if a field outside the MRVS is edited, then you can calculate the value for the variable outside the MRVS (just with client script). Because outside of the MRVS, you can get the values from the MRVS.

Would that be an alternative?

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

Yes, i am not looking to get the values listed inside of the MRV but outside of it

 

from this posting they show how but i am not able to make it work for the record producer

https://community.servicenow.com/community?id=community_question&sys_id=885b107adb7fffccf7fca851ca961970&feedbacktype=reply

No that's about making the sum after you submitted the record. While you wrote that you want this before submitting? Again: not possible if you want to update the variables outside your MRVS, while you are adding rows inside your MRVS. It is possible if you change a variable after this, outside your MRVS.

If changing your requirement to do this after submitting: don't go for onSubmit Client Script. Go for Server Side instead.

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

do you have a suggestion on how i can do this?

i created a BR

(function executeRule(current, previous /*null when async*/) {
var grMRVSAnswer = new GlideRecord('sc_multi_row_question_answer');
grMRVSAnswer.addEncodedQuery('parent_id=' + current.getUniqueValue() + '^item_option_new=85d39b5e1b6c6410548fea4abc4bcbac'); // sys_id of amount in the MRV
grMRVSAnswer._query();

var totalInt = 0;
while(grMRVSAnswer._next()) {
if(grMRVSAnswer.value != '') {
// var amountInt = grMRVSAnswer.value.replace(',', '.');

totalInt = parseFloat(totalInt) + parseFloat(amountInt);
}
}

current.variables.u_total = totalInt.toString(); // variable outside of the MRV to display the totals
current.update();


})(current, previous);

 

but it doesnt seem to work