Skip to main content

Service Catalog: Multi-line variable set with reference field

In this example we populate a group members box based on a selected group:

group field:

multi-line variable set:

setting up the variable set:

in this example the variable is of type multi-line and contains a reference variable (reference on sys_user)

how to populate the box based on the group selected:

onchange client script on the 'group' field with the variable set internal name highlighted in yellow:

//perform ajax, await result var gaGlideAjax = new GlideAjax ("CatalogueHelper"); gaGlideAjax.addParam("sysparm_name", "getGroupMembers"); gaGlideAjax.addParam("sysparm_group", g_form.getValue("group_ref")); gaGlideAjax.getXMLAnswer(function processAnswer(answer) { try{ var oResult = JSON.parse(answer); g_form.setValue("group_name",; g_form.setValue("group_manager",oResult.manager, oResult.dv_manager); g_form.setValue("group_email",; g_form.setValue("cost_center",oResult.cost_center, oResult.dv_cost_center); g_form.setValue("group_type",oResult.type); g_form.setValue("description",oResult.description); g_form.setValue("u_group_members",JSON.stringify(oResult.users)); }catch (e){} });

AJAX script include function (client callable):

var CatalogueHelper = Class.create(); CatalogueHelper.wfDebug = function(sMessage,sMessageLevel){ sMessageLevel = sMessageLevel || "info"; var oWorkflow = (typeof workflow == "undefined") ? false:workflow; var sDebugLevel = gs.getProperty("STP.WFDebug") || "info"; if (oWorkflow){ switch (sDebugLevel){ case "debug": if (sDebugLevel == sMessageLevel) oWorkflow.scratchpad.aLog.push (sMessage); case "info": if (sDebugLevel == sMessageLevel) oWorkflow.scratchpad.aLog.push (sMessage); case "none":break; } } }; CatalogueHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, { getGroupMembers: function(sGroupID){ sGroupID = this.getParameter ("sysparm_group") || sGroupID || ""; if (sGroupID == "") return; //Do nothing var grGroupGlideRecord = new GlideRecord("sys_user_group"), oResult = {"manager":"", "email":"", "provider":"", "type":"", "description":"", "users":[]}; if (!grGroupGlideRecord.get(sGroupID)) return; = grGroupGlideRecord.getValue("name") || ""; oResult.manager = grGroupGlideRecord.getValue("manager") || ""; oResult.dv_manager = grGroupGlideRecord.getDisplayValue("manager") || ""; = grGroupGlideRecord.getValue("email") || ""; oResult.type = grGroupGlideRecord.getValue("type") || ""; oResult.description = grGroupGlideRecord.getValue("description") || ""; oResult.cost_center = grGroupGlideRecord.getValue("cost_center") || ""; oResult.dv_cost_center = grGroupGlideRecord.getDisplayValue("cost_center") || ""; var grMembersGlideRecord = new GlideRecord("sys_user_grmember"); grMembersGlideRecord.addEncodedQuery ("^group=" + sGroupID); grMembersGlideRecord.orderBy("user.last_name"); grMembersGlideRecord.query(); while ({ oResult.users.push ({"user":grMembersGlideRecord.getValue("user")}); } return JSON.stringify(oResult); }, type: 'CatalogueHelper' });


Popular posts from this blog

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue'" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });

GlideRecord setValue

setValue(String name, Object value) Sets the specified field to the specified value. Normally a script would do a direct assignment, for example,  gr.category = value . However, if in a script the element name is a variable, then  gr.setValue(elementName, value)  can be used. When setting a value, ensure the data type of the field matches the data type of the value you enter. This method cannot be used on journal fields. If the value parameter is null, the record is not updated, and an error is not thrown!/api_doc?v=madrid&id=r_GlideRecord-setValue_String_Object