Populate Multi row variable set using script

Alon Grod
Tera Expert

Hi,

 

i have a MRVS on my catalog item with two variables of type Reference. In addition, i have a variable of type reference on my catalog item itself. How can I populate one of the variables in the MRVS with the value of the variable in my catalog item. Both the variable from the MRVS and the variable from the catalog item are referenced to the same table

1 ACCEPTED SOLUTION

RaghavSh
Kilo Patron

This should be quite simple considering you will populate your catalog item variable before  MRVS.

 var user1 = g_service_catalog.parent.getValue("user");  // user is. variable in catalog item
 g_form.setValue('user_mrvs', user1);  // user_mrvs is varaiable on multi row variable set

** this is on load client script on MRVS**
**Note : The on Load client script works on MRVS when you click on Add button**

Raghav
MVP 2023

View solution in original post

5 REPLIES 5

Its_Azar
Tera Guru

Hi there @Alon Grod 

write a catalog client script like this

 

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

    var catItemRef = g_form.getValue('catalog_item_ref_variable'); 

    if (catItemRef) {
       
        var mrvs = g_form.getValue('needed_variables'); 
        var mrvsObj = JSON.parse(mrvs);

        if (mrvsObj.length > 0) {
            mrvsObj[0].hidden_catalog_item_id = catItemRef; 
        } else {
            
            mrvsObj.push({
                hidden_catalog_item_id: catItemRef
            });
        }

        g_form.setValue('needed_variables', JSON.stringify(mrvsObj));
    }
}
☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India