- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 12:05 AM
I received a requirement that in the incident form, if Subcategory 1 (u_subcategory) is SAP, only APO, ECC, OpenText, and SAP-Security should be shown in the CI field.
I created a Client Script, but there's an error: onChange script error: TypeError: g_form.setDependentField is not a function function () { [native code] }
Client Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 12:43 AM
You will need to adjust this in the reference qualifier of the cmdb_ci field. Add a check to the subcategory field and limit the choices.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 12:43 AM
You will need to adjust this in the reference qualifier of the cmdb_ci field. Add a check to the subcategory field and limit the choices.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 02:01 AM
@Mark Manders
How can I achieve that? Since there are other Category and Subcategory that using the CI field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 01:15 AM
Hi @Vengeful ,
As suggested by @Mark Manders you need to edit the reference qualifier to return only specificed CIs in Config item field.
Create a script include which returns only 'SAP, only APO, ECC, OpenText, and SAP-Security' realted CIs if the category is relevent to it.
start with script include and reference qualifier and let us know were your struck...
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:36 PM
Here is the Script Include
Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Get the value of the u_subcategory field
var subcategory = g_form.getValue('u_subcategory');
// Check if the u_subcategory is SAP
if (subcategory.toLowerCase() === 'sap') {
// Call the Script Include to get relevant CIs
var ga = new GlideAjax('FilterCIsByCategorySAP');
ga.addParam('sysparm_name', 'getRelevantCIs');
ga.addParam('sysparm_subcategory', subcategory);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var ciList = JSON.parse(answer);
// Create a query to limit the CI field
var ciQuery = 'sys_idIN' + ciList.map(function(ci) {
return ci.sys_id;
}).join(',');
g_form.setQuery('cmdb_ci', ciQuery);
});
} else {
// Clear the query if the subcategory is not SAP
g_form.clearOptions('cmdb_ci');
}
}
This is the dictionary of Configuration Item in Incident form