How to Use Multirow Variable Sets (MRVS) 1

Alex78
Tera Contributor

Hi Team, 

Good Morning!

when i selected department is xyz then it should be check user table which user is same department and auto populate all user on MRVS details

 

Alex78_0-1702201066674.png

 



Thank You!



2 REPLIES 2

Anand Kumar P
Giga Patron
Giga Patron

Hi @Alex78 ,

You have to create one onchange client script on Department variable and pass to script include and get user details and populate in MVS varibles.

Catalog Client Script: 
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.multipop'); //calling script include
ga.addParam('sysparm_name', 'fetchDetails'); //Script include function
ga.addParam('sysparm_dpt', newValue); //On change Value
ga.getXML(setUserDet);
function setUserDet(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('get_employee_details', answer); // Add your Variable set Name
}
}

Client callable Script Include:
var multipop = Class.create();
multipop.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fetchDetails : function()
{
var dataArr = [];
var data = {};
var deptId = this.getParameter('sysparm_dpt');
var gr = new GlideRecord("sys_user");
gr.addQuery('department',deptId);
gr.addQuery('active',true);
gr.query();
while(gr.next())
{
data = {};
data.employee = gr.sys_id.toString();
data.mobile_no = gr.mobile_phone.toString();
data.email_id = gr.email.toString();
dataArr.push(data);
}
return JSON.stringify(dataArr);
},
type: 'multipop'
});


Mark it helpful and solution proposed if it serves your purpose.

Thanks,

Anand

 

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Alex78 ,

 

You can try the onChange client script & script include for this requirement

 

Script Include:

 

// UserQueryScriptInclude

var UserQueryScriptInclude = Class.create();

 

UserQueryScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

    getUsersByDepartment: function () {

        var department = this.getParameter('sysparm_department');

 

        var userGr = new GlideRecord('sys_user');

        userGr.addQuery('department', department);

        userGr.query();

 

        var users = [];

        while (userGr.next()) {

            users.push({

                value: userGr.sys_id

            });

        }

 

        return users;

    }

});

 

Client Script:

 

// Catalog Client Script

function onLoad() {

    var selectedDepartment = g_form.getValue('department_field');

 

    if (selectedDepartment) {

        var ga = new GlideAjax('UserQueryScriptInclude');

        ga.addParam('sysparm_name', 'getUsersByDepartment');

        ga.addParam('sysparm_department', selectedDepartment);

        ga.getXML(populateMRVS);

    }

}

 

function populateMRVS(response) {

    var users = response.responseXML.documentElement.getAttribute("answer");

   

// Clear existing MRVS values

        g_form.clearOptions('mrvs_field'); // Replace 'mrvs_field' with the actual MRVS field name

 

        // Populate MRVS with users from the selected department

        while (userGr.next()) {

            g_form.addOption('mrvs_field', users.value);

        }

}

 

Thanks,

Danish