Client script on MultiRow variable

dhanashree2011
Tera Contributor

Hi All,

I have a requirement where i should auto populate Total Cost of all amount in $ field from Multi row Variable set.

What kind of Client script needs to be configured.

 

dhanashree2011_0-1716560111744.png

 

I have tried he solution below but it didn't work

https://www.servicenow.com/community/developer-forum/multi-row-variable-set-client-script-to-do-some...

 

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hello @dhanashree2011 

I haven't tested the Willem solution but you can also try something using onSubmit() client script on catalog item which will calculate all the entries in the MRVS and append it to the variable in the catalog form. Use the below script if you want to implement with onSubmit.

function onSubmit() {
    var totalAmount = 0;
    var mrvsData = g_form.getValue('u_mrvs'); //give MRVS internal name
    var mrvsParse = JSON.parse(mrvsData);
    for (var i = 0; i < mrvsParse.length; i++) {
        totalAmount += parseInt(mrvsParse[i].u_amount);
    }
    g_form.setValue("total_amount", totalAmount);
    return false; //remove this after testing
}

Quick walk-through:

MRVS total.gif

 Hope it helps:)

Thanks,
Murthy

View solution in original post

2 REPLIES 2

Murthy Ch
Giga Sage

Hello @dhanashree2011 

I haven't tested the Willem solution but you can also try something using onSubmit() client script on catalog item which will calculate all the entries in the MRVS and append it to the variable in the catalog form. Use the below script if you want to implement with onSubmit.

function onSubmit() {
    var totalAmount = 0;
    var mrvsData = g_form.getValue('u_mrvs'); //give MRVS internal name
    var mrvsParse = JSON.parse(mrvsData);
    for (var i = 0; i < mrvsParse.length; i++) {
        totalAmount += parseInt(mrvsParse[i].u_amount);
    }
    g_form.setValue("total_amount", totalAmount);
    return false; //remove this after testing
}

Quick walk-through:

MRVS total.gif

 Hope it helps:)

Thanks,
Murthy

Thanks.. This worked