Would like to know in details how catalog item form variable can be made accessible in MRVS

saikatmitra
Tera Contributor

Hi Team,

 

I have searched a lot of ways but nothing works. Would like to know in details how catalog item form variable can be made accessible in MultiRow Variable set. I have tried with session variable but not sure how it works. Any detail solution will be helpful as I am new in using MRVS.

 

 

There is a Requested For reference field is in my catalog item form and a similar reference field is there in my MRVS. requirement is onChange or onLoad, the catalog item variable value to be set in MRVS variable as well.

6 REPLIES 6

Moin Kazi
Kilo Sage
Kilo Sage

Hi @saikatmitra ,

 

You can collect info in array object format then you can directly store in MRVS with g_from.setValue('mrvs_internal_name', your_array_object); 

 

Please see below example - 

Client script - Once manager selected all reportee's details will be populated in MRVS -

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('x_1030577_image_0.ManagerReporteesUtil');
    ga.addParam('sysparm_name', 'getReportees');
    ga.addParam('sysparm_id', newValue); // Pass the manager's sys_id (newValue)
    ga.getXMLAnswer(response);
    function response(response) {
		/* response = "[{"name":"Adela Cervantsz","email":"adela.cervantsz@example.com","user_id":"adela.cervantsz"},{"name":"Abel Tuter","email":"abel.tuter@example.com","user_id":"abel.tuter"},{"name":"Aileen Mottern","email":"aileen.mottern@example.com","user_id":"aileen.mottern"},{"name":"Abraham Lincoln","email":"abraham.lincoln@example.com","user_id":"abraham.lincoln"}]" */
        // Now populate the MRVS with reportee details
        var mrvsName = 'all_manager_reportees'; // Your MRVS variable name
        g_form.clearValue(mrvsName); // Clear existing values in the MRVS        
	g_form.setValue('all_manager_reportees', response);   // Populate reportee details    
    }
}

Client Callable Script include: 

var ManagerReporteesUtil = Class.create();
ManagerReporteesUtil.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getReportees: function() {
        var managerSysId = this.getParameter('sysparm_id');
        var reportees = [];
        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('manager', managerSysId);
        userGr.query();
        while (userGr.next()) {
            reportees.push({
                name: userGr.name.toString(),
                email: userGr.email.toString(),
                user_id: userGr.user_name.toString()
            });
        }
        return JSON.stringify(reportees);
    },
    type: 'ManagerReporteesUtil'
});

 

Output -

MoinKazi_0-1729357772721.png

 

 

Please mark my answer as solution as accepted and indicate whether it was helpful in resolving your queries.

 

Regards

Moin

Hi Moin,

 

Thanks for your advise. Unfortunately both the links have not worked. I have found an alternative way where I have stored the session client data in an property in onCall client script and later reading the property from the Multi Row Variable Set Reference Qualifier and also set it as its default value. Could you please elaborate all the MVRS variables are of string type or not and what are the variable names so that I can try it once again.