can i write onchange client script on single row variable for MRVS

sonali jori2
Tera Contributor

I have currency variable in single row variable. and total price in MRVS. I want auto populate total price based on currency selected.is it possible?

6 REPLIES 6

I am pasting here script include and client script.

script include-

 prefilUnitPriceEUR: function() {
                var userCurrency = this.getParameter('sysparm_ID');
                var userPrice = this.getParameter('sysparm_value');

                var conv = new sn_currency.GlideCurrencyConverter(userCurrency, 'EUR');
                conv.setAmount(userPrice);
                var convertValues = conv.convert();
                var unitPrice = convertValues.getAmount();
                return unitPrice;
            },

                type: 'UnitPriceEUR'
            });
 
 
onchange client script:-
 
 if (isLoading || newValue == '') {
        return;
    }


    //Type appropriate comment here, and begin script below
    var f1 = g_form.getValue('total_price_of_product');
    var f2 = g_form.getValue('quantity');
    var userCurrency = g_form.getValue('currency2');
    var userPrice = (f1) / (f2);
    var ga = new GlideAjax('UnitPriceEUR');
    ga.addParam('sysparm_name', 'prefilUnitPriceEUR');
    ga.addParam('sysparm_ID', userCurrency);

    ga.addParam('sysparm_value', userPrice);

    ga.getXML(myCallBack);
}

function myCallBack(response) {
    var eurPrice = response.responseXML.documentElement.getAttribute("answer");
    g_form.setValue('unit_price_in_eur', eurPrice);



}

@sonali jori2 

it's not direct. you will have to tweak the client script on MRVS to get outside variable value

links I shared should help you

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader