access variable inside MRVS

vandanasaluja
Tera Contributor

Hi team,

 

I have a variable Requested for  which is part of the User field variable set, and I have affected for the variable which is part of MRVS now i want to populate the affected for field with all users where manager is equal to requested for.

 

 

I tried creating a script include and calling it via ref qualifier but its returning undefined for current.variables.requested_for

8 REPLIES 8

Samaksh Wani
Giga Sage
Giga Sage

Hello @vandanasaluja 

 

Try my approach with exact script :-

 

 

1. Create a Catalog Client Script

  • Type: onChange

  • Applies to Variable: Requested For

  • UI Type: All or Mobile / Service Portal (based on usage)

  • Script:

 

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

    var requestedForSysId = g_form.getValue('requested_for'); 

    var ga = new GlideAjax('GetUsersByManager');
    ga.addParam('sysparm_name', 'getUsers');
    ga.addParam('sysparm_manager', requestedForSysId);
    ga.getXMLAnswer(function(response) {
        var userList = JSON.parse(response);
        
    
        g_form.clearMultiRowVariableSet('your_mrvs_variable_name'); // replace with actual MRVS name

        for (var i = 0; i < userList.length; i++) {
            var row = g_form.addNewMultiRow('your_mrvs_variable_name'); // replace with MRVS name
            g_form.setValueInMultiRow(row, 'affected_for', userList[i].sys_id); // replace 'affected_for' with actual field name
        }
    });
}

 

 

2. Create a GlideAjax Script Include

  • Name: GetUsersByManager

  • Set to Client Callable: true

 

var GetUsersByManager = Class.create();
GetUsersByManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    getUsers: function() {
        var managerId = this.getParameter('sysparm_manager');
        var result = [];

        var gr = new GlideRecord('sys_user');
        gr.addQuery('manager', managerId);
        gr.query();

        while (gr.next()) {
            result.push({
                name: gr.getValue('name'),
                sys_id: gr.getValue('sys_id')
            });
        }

        return JSON.stringify(result);
    }

});

 

Pls mark my solution as accept and thumbs up if you find it helpful. It will help other users on community to find helpful response.

 

 

Regards,

Samaksh Wani

 

Shraddha Kadam
Mega Sage

Hello @vandanasaluja ,

 

Can you please share your script include

If my response was helpful, please mark it as correct and helpful.
Thank you.

Shruti
Mega Sage
Mega Sage

Tried but it didnot worked