Access multi row variables outside variable set

Ruchi Kumari1
Tera Expert

Hi,
I have a ask where i need to display names of asset tagged to user, whenever any user is selected.

1. User field is of type list collector. So multiple users can be selected in one request.
2. On select of users I need to display the tagged asset. (Field type of this asset can be decided based on feasibility).

**Work around that i was trying is to use a MVRS (multi row variable set) and populate asset names whenever user is selected in list. In this variable set i have created 2 variables (User, Asset) of single line text field type. I am expected whenever user is selected in list collector, That user and associated asset is populated in this MRVS.

But the challenge is list type field is outside MRVS.
Is this feasible ? Or any other workaround to achieve this (I just want the user selected in list and associated asset is displayed on form)?

Thanks,


15 REPLIES 15

PrashantT
Giga Guru

You need to perform two Steps to achieve the desired Output:

 

Step1: Write the below mentioned client script:

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

        return;

    }

 

    var mrvsVariableName = 'hardware_details'; // Replace your mrvs variable Name 

 

    var gaAsset = new GlideAjax('HardwareDetails'); // Replace the script include name

    gaAsset.addParam('sysparm_name', 'fetchAssetDetails'); // Replace the script include function name

    gaAsset.addParam('sysUserid', newValue); // No need to change anything

 

 

    gaAsset.getXMLAnswer(function(answer) {

 

        g_form.setValue(mrvsVariableName,answer); // No need to change anything

       

    });

 

    //Type appropriate comment here, and begin script below

 

}

 

 

 

Step2: Write the Script include to get the data from server side

 

var HardwareDetails = Class.create(); // Define your script include name

HardwareDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

    fetchAssetDetails: function() { // Replace your script include function name

 

        var userSysid = this.getParameter('sysUserid'); // No need to change anything

 

        var newRecord = [];

 

        var assetUser = new GlideRecord('alm_hardware');

        assetUser.addQuery('assigned_to.sys_id', userSysid);

        assetUser.query();

        while (assetUser.next()) {

            newRecord.push({

                "asset_name": assetUser.getValue("display_name"),

                "assigned_to": assetUser.getDisplayValue("assigned_to")

// Replace your mrvs variable field backend name - asset_name, assigned_to based on your define name in mrvs variable

            });

        }

 

 

        //  gs.addInfoMessage('value of Hardware asset', JSON.stringify(newRecord));

        return JSON.stringify(newRecord);

 

    },

 

    type: 'HardwareDetails' // it will populate automatically 

});

 

 

Please mark my response helpful if it is correct