- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
53m ago
The Issue
A reference variable within a Multi-Row Variable Set (MRVS) is dependent upon the value of a catalog item variable.
Workaround
Create another variable in the MRVS. Then, in an onLoad script of the MRVS, populate this other variable on every row with the value of the catalog item variable to use in the reference qualifier (...current.variables.var_name).
The downside to this workaround is creating and populating an unnecessary variable that can only be hidden in the Add/Edit Row dialog window, as all MRVS variables are always shown when a MRVS is displayed.
A Solution
A simple approach is to use session data to complete the reference qualifier.
A Detailed Example
We have a catalog item reference variable named v_manager that is a reference to the sys_user table. In the MRVS we have a reference variable named v_employee that is a reference to the sys_user table. When adding or editing rows on the MRVS, before submitting the request and after, we should always only be able to select user records that are active and have a Manager that is the user selected in the catalog item variable.
If the Employee variable was just another variable in the catalog item, the reference qualifier would easily be:
javascript:'active=true^manager=' + current.variables.v_manager;
In a MRVS, since 'current' refers to the MRVS, and there is not (yet?) a similar method for reference qualifiers to access catalog item variables, we need to create a way following these simple steps:
1. Set the advanced reference qualifier on the MRVS variable to something like:
javascript:'active=true^manager=' + session.getClientData('v_manager');
Example 2.1: Use your catalog item variable name in place of v_manager.
2. Create a catalog client script that applies to the Variable Set:
function onLoad() {
var catItemVarName = 'v_manager'; //catalog item variable name
var catItemVarValue = g_service_catalog.parent.getValue(catItemVarName);
var ga = new GlideAjax('refQualUtils'); //client callable script include name
ga.addParam('sysparm_name', 'setSessionData'); //function in script include
ga.addParam('sysparm_cat_item_var_name', catItemVarName);
ga.addParam('sysparm_cat_item_var_value', catItemVarValue);
ga.getXMLAnswer(getResponse);
}
function getResponse(response) {
//do nothing
}
Example 2.2: Update the script as needed with your catalog item variable name, script include name, and a new function name.
3. Create a Client callable script include to retrieve and set session data from the client script.
var refQualUtils = Class.create();
refQualUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setSessionData: function() {
var catItemVarName = this.getParameter('sysparm_cat_item_var_name');
var catItemVarValue = this.getParameter('sysparm_cat_item_var_value');
var session = gs.getSession().putClientData(catItemVarName, catItemVarValue);
return;
},
type: 'refQualUtils'
});
Example 2.3: Since the catalog client script and script include use parameters, they can be re-used in every instance of this solution.
When the Add or Edit Rows MRVS window opens, the value of the catalog item variable is stored in the session data with the variable name, then the reference qualifier can retrieve the session data. See the ServiceNow Docs on GlideSession for more information about this API.
Now you can include values from catalog item variables in MRVS variable reference qualifiers!
