- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hello, community! I'm trying to sum variables (Value) within MRV and send that sum to a variable (Sum) outside of MRV.
I developed this client script within the record producer, but it's not working:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var mrvsRows = g_form.getValue("nota_fiscal");
if (!mrvsRows) {
g_form.setValue("sum", 0);
return;
}
var rows = JSON.parse(mrvsRows);
var sum = 0;
for (var i = 0; i < rows.length; i++) {
var cost = rows[i]["value"];
if (cost) {
sum += parseFloat(cost) || 0;
}
}
g_form.setValue("sum", sum);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
this link has approach and you can enhance
Populate field outside MRVS with a total sum of fields inside MRVS
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
on change of what field are you executing this JS?
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Since MRV didn't appear, I left it blank.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Suggest you to create a onsubmit client script within MRVS and add the below script to update the parent
function onSubmit() {
if (isLoading) {
return;
}
var mrvsRows = parent.g_form.getValue("nota_fiscal");
if (!mrvsRows) {
parent.g_form.setValue("sum", 0);
return;
}
var rows = JSON.parse(mrvsRows);
var sum = 0;
for (var i = 0; i < rows.length; i++) {
var cost = rows[i]["value"];
if (cost) {
sum += parseFloat(cost) || 0;
}
}
parent.g_form.setValue("sum", sum);
}
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
If you change this line, you'll get something - onChange of whatever variable this is triggering on, provided the MRVS is populated prior to that variable changing.
var cost = rows[i].value;
If you're looking for a way to make sure this count is accurate when rows are added, edited, or removed from the MRVS, check out these options:
https://www.servicenow.com/community/developer-forum/actions-after-a-mrvs-update/td-p/3031014