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",oResult.name); g_form.setValue("group_manager",oResult.manager, oResult.dv_manager); g_form.setValue("group_email",oResult.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; oResult.name = grGroupGlideRecord.getValue("name") || ""; oResult.manager = grGroupGlideRecord.getValue("manager") || ""; oResult.dv_manager = grGroupGlideRecord.getDisplayValue("manager") || ""; oResult.email = 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 ("user.active=true^group=" + sGroupID); grMembersGlideRecord.orderBy("user.last_name"); grMembersGlideRecord.query(); while (grMembersGlideRecord.next()){ oResult.users.push ({"user":grMembersGlideRecord.getValue("user")}); } return JSON.stringify(oResult); }, type: 'CatalogueHelper' });

Comments

Popular posts from this blog

GlideRecord setValue

variable advanced reference qualifier example

URL link in addInfoMessage