- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 07:38 AM
Hi Team,
I would really appreciate any help/guidance on how to achieve/modify the script I have, to achieve this.
On my Incident form I have a field for Service (business_service) and Business Application (u_business_application).
I want to put a Reference Qualifier on the Service (business_service) field, so that when Business Application is populated, the only options that show in the Service field are children of the parent Business Application.
I currently have the following script include and reference qualifier, which can be used to achieve the same, for showing CI's that relate to a service offering, but how can I amend this script include and the related reference qualifier javascript, so that I can achieve a similar process for only showing Service related to the Business Application.
Here is the Reference Qualifier Javascript I need to modify:
javascript: new IncidentUtils().getCis(current.service_offering);
And Here is associated script include I am wanting to modify:
var IncidentUtils = Class.create();
IncidentUtils.prototype = {
getCis: function(so) {
var getCiArr = [];
if (so) {
var cm = new GlideRecord('cmdb_ci');
cm.addEncodedQuery('sys_class_name=service_offering');
cm.addQuery('sys_id', so);
cm.query();
if (cm.next()) {
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent', cm.sys_id);
gr.query();
while (gr.next()) {
getCiArr.push(gr.child.sys_id.toString());
}
return "sys_idIN" + getCiArr.join(',');
}
}
},
type: 'IncidentUtils'
};
Thanks very much - any help/guidance, very much appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 01:01 PM
Reference qualifier for Service field dictionary: Replace "u_business_application" field with your business application field name if its different
javascript: new IncidentUtils().getServiceList(current.u_business_application);
Add below code in "IncidentUtils" script include
getServiceList: function(business_application) {
var getServices = [];
if (business_application) {
var grCIRelationsip = new GlideRecord('cmdb_rel_ci');
grCIRelationsip.addQuery('parent.sys_class_name=cmdb_ci_business_app');
grCIRelationsip.addQuery('parent', business_application);
grCIRelationsip.query();
while (grCIRelationsip.next()) {
getServices.push(grCIRelationsip.getValue('child'));
}
return "sys_idIN" + getServices.join(',');
}
},
I tested this script include in PDI & its working
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! This will help others as well 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:14 AM
@WazzaJC Could you please share table name of Service & business application ? How are they related to each other ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:26 AM
Hi Sandeep,
yes of course - thank you for coming back to me.
'Services' is the standard OOTB Services table as per PDI (cmdb_ci_service)
'Business Applications' is the standard OOTB Business Applications table as per PDI (cmdb_ci_business_app)
They are related as Parent and Child in the standard OOTB 'CI Relationships' Table (cmdb_ci_rel)
Thanks again for any help/guidance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 11:24 AM
Hi @WazzaJC ,
Try this.
Reference qualifier:
javascript: new IncidentUtils().getServiceCIs(current.u_business_application);
And, add another method called "getServiceCIs" to your Script Include like the one below,
getServerCIs: function(ba) {
var getCiArr = [];
if (ba) {
var cm = new GlideRecord('cmdb_rel_ci');
cm.addQuery('parent.sys_class_name=cmdb_ci_service');
cm.addQuery('child', ba);
cm.query();
while (cm.next()) {
getCiArr.push(gr.parent.sys_id.toString());
}
return "sys_idIN" + getCiArr.join(',');
}
},
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2023 12:13 PM
Hi Anvesh - many thanks for trying to help, much appreciated.
Can you try this on your own PDI and confirm is this script set up works for you?
I feel it is getting close as looks to almost be working but it is still not working for me?
If you could try on your side and confirm this definitely works on your PDI - many thanks Anvesh.