- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 06-09-2024 03:04 AM
Hi All,
The goal of this article is to provide detailed steps to show the reference field's values based on the drop down field value.
Use Case:
In the catalog item, There are 2 fields:
1. 'Environment' of type select box with choices(Dev and Prod)
2. 'List of CIs' which is of reference type referencing to [cmdb_ci] table
On the selection of Environment as Dev, the 'List of CIs' will be showing all the CIs of environment Development and similarly if Environment is selected as Prod, the List of CIs will show the list of environment Production.
Implementation Steps:
We will utilize the advance reference qualifier of the 'List of CIs' field in this scenario and call the script include and pass the service portal selected Environment value as parameter.
Script Include:
Client callable - true
var CustomQueryUtils = Class.create();
CustomQueryUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
showEnvCIs: function(getEnvVal) {
var listOfCIs = '';
var grCI = new GlideRecord('cmdb_ci');
grCI.addQuery('environment', getEnvVal);
grCI.query();
while (grCI.next()) {
listOfCIs = 'environment=' + getEnvVal;
return listOfCIs;
}
},
type: 'CustomQueryUtils'
});
In the variable 'List of CIs', we will define in the advance reference qualifier as below:
javascript: new CustomQueryUtils().showEnvCIs(current.variables.environment);
The result will now show the list of CIs based on the Environment selected. If Prod, then only environment type Production will be visible in the list of CIs.
If we want to pass multiple values as parameter, that could be achieved as below:
Advanced reference qualifier of 'List of CIs' :
javascript: new CustomQueryUtils().showEnvCIs(current.variables.environment, current.variables.division);
Client callable Script Include:
var CustomQueryUtils = Class.create();
CustomQueryUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
showEnvCIs: function(getEnvVal, getDivisionVal) {
//Logic goes here
},
type: 'CustomQueryUtils'
});
Here,
'getEnvVal' will have the value selected in the variable Environment
'getDivisionVal' will have the value selected in the variable Division
If this helped you in any way, Please hit Helpful. Thanks.
- 2,730 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is "getEnvVal" an out-of-the-box function? What if I need to retrieve the value of a custom table in the same scope? Thanks.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @C_dric Chen ,
getEnvVal is just parameters of the function. You can rename it as you wish. It will hold the value which we are passing from the below line:
javascript: new CustomQueryUtils().showEnvCIs(current.variables.environment);
Here, current.variables.environment is representing the 'environment' variable's value selected.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Another question: Is this method supposed to work "List of CIs" is a List field? I tried implementing this method on a List field in my own instance, but it didn't work.