The CreatorCon Call for Content is officially open! Get started here.

In a Record Producer how to sum the amount(currency) field in list of records in the list selector?

Joshua Prakash
Tera Expert

I have created a Record Producer which contains list collector field called "Expense Items"

Expense Items are a records of a table which has "amount" as a field(currency);

How can I get the "amount" of the selected list of expense items and total it to a field(Total Amount) on Record Producer itself before submitting it.

And the "Total Amount" should populate in a form called Expense Report which contains "Sum" field(currency) that is mapped to the above Record producer?

3 REPLIES 3

Satishkumar B
Giga Sage
Giga Sage

Hi @Joshua Prakash 

 

check this:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}

var items = g_form.getReference('expense_items').split(',');
var totalAmount = 0.0;

items.forEach(function(item) {
var amount = parseFloat(g_form.getValue('expense_items.amount', item));
if (!isNaN(amount)) {
totalAmount += amount;
}
});

g_form.setValue('total_amount', totalAmount.toFixed(2));
}

 

----------------------------------------
If my response was useful, please mark as "Accept as Solution" and " Helpful." This action benefits both the community and me.

Error: There is a JavaScript error in your browser console.

Can we do it without getReference?

Yashsvi
Kilo Sage

Hi @Joshua Prakash,

please check below link:

https://www.servicenow.com/community/developer-forum/how-to-sum-field-total-value-from-list-of-recor...

Thank you, please make helpful if you accept the solution.