Pre-populate Multirow Variable Set Values using Catalog Client Script based on Change of Variable
Hello All,
In this article, I will show you how you can add the rows dynamically in MRVS based on the input value of a catalog item.
For this, I have created 1 Record producer(Multirow Test), in which there is one field "Department". And I have 1 Multirow variable set "Get Employee Details", which user has to fill the details of employee.
So once Requestor enter the value in the "Department " field, it will auto populate the Multi row variable set (MRVS) with no of users which is part of the Depart.
e.g. Selected Department - Development
Result: It will give you details of all Employees whose Department is "Development"
For this, we will require 1 catalog client script OnChange on the field (Department), 1 script Include.
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
}
}
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'
});
Output:
Mark the article as helpful and bookmark if you found it useful.
https://www.servicenow.com/community/itsm-articles/pre-populate-multirow-variable-set-values-using-catalog-client/ta-p/2307327
