Skip to content

Commit d718114

Browse files
committed
Business Service Lookup Script Include
This code snippet fetches the business service related to the CI , when the CI is changed in the change_request form.
1 parent 391fcf6 commit d718114

File tree

4 files changed

+65
-55
lines changed

4 files changed

+65
-55
lines changed

Server-Side Components/Business Rules/Validate CI on deployed asset/README.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

Server-Side Components/Business Rules/Validate CI on deployed asset/businessrulescript.js

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Business Service Lookup Fetch When CI Changes
2+
3+
This code snippet dynamically fetches and filters Business Services based on the selected Configuration Item (CI) in the change request forms. It ensures accurate service mapping, improves user experience, and supports compliance in Change Management and other ITSM workflows.
4+
5+
Features
6+
-Filters Business Services based on CI relationships
7+
-Supports Script Includes and Client Script
8+
-Compatible with Change Request forms and scoped apps
9+
-Reusable across multiple catalog items and modules
10+
11+
Use Case
12+
When a user selects a CI (e.g., server, application), the form should only show Business Services linked to that CI. This avoids incorrect selections and enforces service ownership logic. This also checks for orphaned relationships by logging the details in Sytem Logs where a CI has no linked Business Services to avoid empty dropdowns.
13+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/** Client callable script include */
2+
var GetServiceDetails = Class.create();
3+
GetServiceDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
4+
type:'GetServiceDetails',
5+
getService: function() {
6+
var ciSysId = this.getParameter('sysparm_ci_sys_id');
7+
gs.log('GetServiceDetails called for CI: ' + ciSysId);
8+
9+
var result = {
10+
businessService: ''
11+
};
12+
13+
// Find Business Service via cmdb_rel_ci
14+
var rel = new GlideRecord('cmdb_rel_ci');
15+
rel.addQuery('child', ciSysId);
16+
rel.query();
17+
if (rel.next()) {
18+
var bs = new GlideRecord('cmdb_ci_service');
19+
if (bs.get(rel.parent.toString())) {
20+
result.businessServiceId = bs.getUniqueValue();
21+
result.businessServiceName = bs.getDisplayValue();
22+
23+
} else {
24+
gs.log('No Business Service relationship found for CI: ' + ciSysId);
25+
result.businessService = 'No Business Service linked';
26+
}
27+
28+
}
29+
30+
return JSON.stringify(result);
31+
},
32+
33+
});
34+
35+
36+
/**onChange Client Script on Change_Request form when CI changes */
37+
38+
function onChange(control, oldValue, newValue, isLoading) {
39+
if (isLoading || newValue == '') {
40+
return;
41+
}
42+
43+
var ga = new GlideAjax('GetServiceDetails');
44+
ga.addParam('sysparm_name', 'getService');
45+
ga.addParam('sysparm_ci_sys_id', newValue);
46+
ga.getXML(callScriptInclude);
47+
48+
function callScriptInclude(response){
49+
var answer = response.responseXML.documentElement.getAttribute("answer");
50+
}
51+
52+
}

0 commit comments

Comments
 (0)