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

didnt work, here is the screen shots of the BR: (i should not this is in a record producer)

find_real_file.png

 

find_real_file.png

 

Okay,

1- First go to "sc_multi_row_question_answer" table by typing sc_multi_row_question_answer.LIST in left filter navigator.

2 - Filter the record with applicable question, by right click and click show matching

3- Right click on filter and copy query( we will use in script). screenshot below

find_real_file.png

 

Could you run below in background script and check if you are able to print total

var current = new GlideRecord("u_tester");
if(current.get("90d378ff2f2860106f36e36ef699b695")){ // replace sys_id with a record sys_id in u_tester table
var grMRVSAnswer = new GlideRecord('sc_multi_row_question_answer');
grMRVSAnswer.addEncodedQuery('parent_id=' + current.getUniqueValue() + '^item_option_new=0f9338ff2f2860106f36e36ef699b60e'); // replace "item_option_new=0f9338ff2f2860106f36e36ef699b60e" with query copied in step 3
grMRVSAnswer._query();
var totalInt = 0;
while(grMRVSAnswer._next()) {
if(grMRVSAnswer.value != '') {
var amountInt = grMRVSAnswer.value;
totalInt = parseFloat(totalInt) + parseFloat(amountInt);
}
}
gs.log(totalInt);
}

 

Let me know results.

 

where do i find the log for this

Hi Peter,

You have to run this in background script, the result will be on screen. Screenshot attached.

find_real_file.png

 

You need to replace, details like table, sys_id and filter as mentioned in my previous reply.