On Change Client Script for Catalog Item Multi Row Variable Set

Scott29
Kilo Sage

Hello, I have the below multi row variable set. How can I have the "Total Weight" and "Total Price" automatically calculate once "Unit Weight" is populated.

 

"Total Weight" = "Quantity" x "Unit Weight"

"Total Price" = "Quantity" x "Unit Price"

Scott29_0-1747934088094.png

 

1 ACCEPTED SOLUTION

harish41
Tera Guru

Hi,

You can achieve this by utilizing onChange client script in MRVS

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

    var quauntiy = g_form.getValue('u_quantity');;
    var unit_price = g_form.getValue('u_unit_price');
    var unit_weight = g_form.getValue('u_unit_weight');

    if (unit_weight != '') {
        var total_weight = quauntiy * unit_weight;
        var total_price = quauntiy * unit_price;
        g_form.setValue('u_total_weight', total_weight);
        g_form.setValue('u_total_price', total_price);
    } else {
        g_form.showFieldMsg('u_unit_weight', '...Your own message'); // optional step

    }
}

 

 

 

Mark as correct and helpful if it solved your query.

Regards,
Harish

View solution in original post

3 REPLIES 3

harish41
Tera Guru

Hi,

You can achieve this by utilizing onChange client script in MRVS

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

    var quauntiy = g_form.getValue('u_quantity');;
    var unit_price = g_form.getValue('u_unit_price');
    var unit_weight = g_form.getValue('u_unit_weight');

    if (unit_weight != '') {
        var total_weight = quauntiy * unit_weight;
        var total_price = quauntiy * unit_price;
        g_form.setValue('u_total_weight', total_weight);
        g_form.setValue('u_total_price', total_price);
    } else {
        g_form.showFieldMsg('u_unit_weight', '...Your own message'); // optional step

    }
}

 

 

 

Mark as correct and helpful if it solved your query.

Regards,
Harish

Could you mark my response as correct or helpful if it solved your query and close the thread so that it benefits future readers.

Regards
Harish

JenniferRah
Mega Sage

Add a client script on your MRVS that runs when Unit Weight is changed. In the client script, set the values of Total Weight and Total Price.