Skip to content

Commit 8248467

Browse files
authored
Dynamically update reference qualifier (#1127)
* Create readme.md * Create Script Include.js * Create Variable Set onLoad.js * Create Catalog Item onLoad.js * Update readme.md
1 parent 5402607 commit 8248467

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function onLoad() {
2+
var filterString = 'sys_class_name=cmdb_ci_ip_router^ORsys_class_name=cmdb_ci_ip_switch^ORsys_class_name=cmdb_ci_vpn' //Reference qualifier for this Catalog Item
3+
//alternate method for Service Portal only
4+
// if (window == null){ //Service Portal method
5+
// var setfilter = g_list.get('v_configuration_item');
6+
// setfilter.setQuery(filterString);
7+
// } else { //native UI method
8+
var ga = new GlideAjax('refQualUtils'); //Client callable Script Include Name
9+
ga.addParam('sysparm_name', 'setSysProp'); //Function in Script Include
10+
ga.addParam('sysparm_sys_prop_name', 'sr.ref_qual.ci'); //System Property Name used in Reference qualifier
11+
ga.addParam('sysparm_sys_prop_value', filterString);
12+
ga.getXML(getResponse);
13+
14+
function getResponse(response) { //to avoid Service Portal 'There is a JavaScript error in your browser console'
15+
var answer = response.responseXML.documentElement.getAttribute("answer");
16+
}
17+
//}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var refQualUtils = Class.create();
2+
refQualUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
setSysProp: function(){
5+
var propertyName = this.getParameter('sysparm_sys_prop_name');
6+
var propertyValue = this.getParameter('sysparm_sys_prop_value');
7+
var property = gs.getProperty(propertyName);
8+
gs.setProperty(propertyName, propertyValue);
9+
return;
10+
},
11+
12+
type: 'refQualUtils'
13+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function onLoad() {
2+
var filterString = 'sys_class_name=cmdb_ci_ip_router^ORsys_class_name=cmdb_ci_ip_switch' //Reference qualifier that was replaced
3+
//alternate method for Service Portal only
4+
// if (window == null){ //Service Portal method
5+
// var setfilter = g_list.get('v_configuration_item');
6+
// setfilter.setQuery(filterString);
7+
// } else { //native UI method
8+
var ga = new GlideAjax('refQualUtils'); //Client callable Script Include Name
9+
ga.addParam('sysparm_name', 'setSysProp'); //Function in Script Include
10+
ga.addParam('sysparm_sys_prop_name', 'sr.ref_qual.ci'); //System Property Name used in Reference qualifier
11+
ga.addParam('sysparm_sys_prop_value', filterString);
12+
ga.getXML(getResponse);
13+
14+
function getResponse(response) { //to avoid Service Portal 'There is a JavaScript error in your browser console'
15+
var answer = response.responseXML.documentElement.getAttribute("answer");
16+
}
17+
//}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
When we have a reference variable that is used in a (single row) variable set, sometimes we want to update the Reference qualifier only for specific Catalog Item(s).
2+
3+
In this example, I have a Configuration item (named v_configuration_item) reference variable (cmdb_ci table) in a single row variable set that has been included in a number of Catalog Items. The simple Reference qualifier for this variable is:
4+
sys_class_name=cmdb_ci_ip_router^ORsys_class_name=cmdb_ci_ip_switch
5+
6+
Let's say for one particular Catalog Item, I also want to include the class of VPN (cmdb_ci_vpn).
7+
8+
To do this without having to create another variable with the new qualifier and hiding the variable set variable, there are some preparation steps, including those which ensure that the other Catalog Items using the variable set are not disrupted:
9+
10+
1) Change the advanced reference qualifier on the variable to: **javascript: gs.getProperty("sr.ref_qual.ci");**
11+
using a System Property Name of your choice
12+
13+
2) Create a System Property with the same Name used in the Reference qualifier, leaving the Value empty.
14+
15+
3) Add the included 'Variable Set onLoad' Catalog Client Script that applies to the Variable set with...
16+
17+
4) The included Client Callable Script Include to update the System Property Value to the Reference Qualifier that was replaced. This Script Include uses parameters for the System Property Name and Value, so it can be re-used in every instance of this solution.
18+
19+
Now that the other Catalog Items using the variable set are still working as they were, all you need to do to update the Reference qualifier on certain Catalog Item(s) is:
20+
21+
5) Add the included 'Catalog Item onLoad' Catalog Client Script that applies to the Catalog Item.
22+
23+
This solution works in both the Native UI and Service Portal. The Catalog Client scripts contain an alternate Service Portal only approach in the commented if block that can be used in conjunction with the native UI approach in the else block. This alternate Service Portal solution was developed in collaboration with Chris Perry.

0 commit comments

Comments
 (0)