Skip to content

Commit a6d1a65

Browse files
authored
MRVS Reference Qualifier Dependent on 1st Row Variable (#1919)
* Create onLoad mrvs Catalog Client Script to run onLoad of the MRVS, not the Catalog Item * Create set session data Script Include to work with reference qualifier and onLoad Catalog Client Script * Create README.md explain usage, reason for Catalog Client Script * Create README.md explain usage and reason for Script Include * Create Script Include moved from server component folder * Update README.md combined client script and script include folders * Delete Server-Side Components/Script Includes/MRVS dependent ref qual 1st row directory combined folders * Rename Script Include to AccountUtils.js * Rename onLoad mrvs to onLoad.js
1 parent 2ac45f4 commit a6d1a65

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var AccountUtils = Class.create();
2+
AccountUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
//Populate the department name from the account in the session data for the reference qualifier to use:
5+
6+
setSessionData: function() {
7+
var acct = this.getParameter('sysparm_account');
8+
var dept = '';
9+
var acctGR = new GlideRecord('customer_account'); //reference table for Account variable
10+
if (acctGR.get(acct)) {
11+
dept = '^dept_name=' + acctGR.dept_name; //department field name on account table
12+
}
13+
14+
var session = gs.getSession().putClientData('selected_dept', dept);
15+
return;
16+
},
17+
18+
type: 'AccountUtils'
19+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This Catalog Client Script and Script Include are used with a reference qualifier similar to
2+
javascript: 'disable=false' + session.getClientData('selected_dept');
3+
4+
The scenario is a MRVS with a reference variable to the customer account table. When an (active) account is selected in the first row, subsequent rows should only be able to select active accounts in the same department as the first account.
5+
6+
The Catalog Client Script will pass the first selected account (if there is one) to a Script Include each time a MRVS row is added or edited. The Script Include will pass the department name to the reference qualifier.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function onLoad() {
2+
//applies to MRVS, not Catalog Item. This will pass the first selected account (if there is one) to a Script Include each time a MRVS row is added or edited
3+
var mrvs = g_service_catalog.parent.getValue('my_mrvs'); //MRVS internal name
4+
var acct = '';
5+
if (mrvs.length > 2) { //MRVS is not empty
6+
var obj = JSON.parse(mrvs);
7+
acct = obj[0].account_mrvs;
8+
}
9+
var ga = new GlideAjax('AccountUtils');
10+
ga.addParam('sysparm_name', 'setSessionData');
11+
ga.addParam('sysparm_account', acct);
12+
ga.getXMLAnswer(getResponse);
13+
}
14+
15+
function getResponse(response) {
16+
//do nothing
17+
}

0 commit comments

Comments
 (0)