How to write the client script

PRAGHATIESH S
Tera Expert

Hi,

I have created one variable "Total" and Multi row variable set "Bill", inside the Bill..created one "Amount" variable.

Now I need to provide the SUM of "Amount" variable into " Total" field.

 

How to write the onchange client script for it

4 REPLIES 4

Soni Tushar
Tera Guru

@PRAGHATIESH S ,

 

Catalog Client Script:

 

function calculateTotal() {
    var totalAmount = 0;

    // Get the Multi-row Variable Set data
    var billData = g_form.getValue('bill'); // 'bill' is the name of the Multi-row Variable Set

    if (billData) {
        var billArray = JSON.parse(billData);

        // Iterate through the rows and sum up the Amount values
        for (var i = 0; i < billArray.length; i++) {
            totalAmount += parseFloat(billArray[i].amount) || 0;
        }
    }
    // Set the Total field with the calculated amount
    g_form.setValue('total', totalAmount.toFixed(2)); // 'total' is the name of your Total field
}

// Bind the calculateTotal function to changes in the Multi-row Variable Set
g_form.onChange('bill', calculateTotal);

/ * Note :
Replace 'bill' with the actual name of your Multi-row Variable Set field.
Replace 'amount' with the actual name of the Amount variable inside the Multi-row Variable Set.
Replace 'total' with the name of the Total field where you want to display the sum. */

 

 

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!

Hi @Soni Tushar 

Thanks for the response. Is it a onLoad or onchange script?

This is onchange Catalog client script 

If I select onchange, I am not able to give the MRVS, ideally it won't be coming.