diff --git a/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/AccountUtils.js b/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/AccountUtils.js new file mode 100644 index 0000000000..602bc20056 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/AccountUtils.js @@ -0,0 +1,19 @@ +var AccountUtils = Class.create(); +AccountUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { + + //Populate the department name from the account in the session data for the reference qualifier to use: + + setSessionData: function() { + var acct = this.getParameter('sysparm_account'); + var dept = ''; + var acctGR = new GlideRecord('customer_account'); //reference table for Account variable + if (acctGR.get(acct)) { + dept = '^dept_name=' + acctGR.dept_name; //department field name on account table + } + + var session = gs.getSession().putClientData('selected_dept', dept); + return; + }, + + type: 'AccountUtils' +}); diff --git a/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/README.md b/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/README.md new file mode 100644 index 0000000000..d700088dc9 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/README.md @@ -0,0 +1,6 @@ +This Catalog Client Script and Script Include are used with a reference qualifier similar to +javascript: 'disable=false' + session.getClientData('selected_dept'); + +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. + +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. diff --git a/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/onLoad.js b/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/onLoad.js new file mode 100644 index 0000000000..6c041330e2 --- /dev/null +++ b/Client-Side Components/Catalog Client Script/MRVS dependent ref qual 1st row/onLoad.js @@ -0,0 +1,17 @@ +function onLoad() { + //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 + var mrvs = g_service_catalog.parent.getValue('my_mrvs'); //MRVS internal name + var acct = ''; + if (mrvs.length > 2) { //MRVS is not empty + var obj = JSON.parse(mrvs); + acct = obj[0].account_mrvs; + } + var ga = new GlideAjax('AccountUtils'); + ga.addParam('sysparm_name', 'setSessionData'); + ga.addParam('sysparm_account', acct); + ga.getXMLAnswer(getResponse); +} + +function getResponse(response) { + //do nothing +}