Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Business Service Lookup Fetch When CI Changes

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.

Features
-Filters Business Services based on CI relationships
-Supports Script Includes and Client Script
-Compatible with Change Request forms and scoped apps
-Reusable across multiple catalog items and modules

Use Case
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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/** Client callable script include */
var GetServiceDetails = Class.create();
GetServiceDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
type:'GetServiceDetails',
getService: function() {
var ciSysId = this.getParameter('sysparm_ci_sys_id');
gs.log('GetServiceDetails called for CI: ' + ciSysId);

var result = {
businessService: ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You define businessService, but later on use businessServiceId and businessServiceName. Please define the right variables and check for unused ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have taken only business service name into account.

};

// Find Business Service via cmdb_rel_ci
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('child', ciSysId);
rel.query();
if (rel.next()) {
var bs = new GlideRecord('cmdb_ci_service');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not take into account CI groups. Consider expanding this to support a CSDM aligned setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I’ve kept the logic focused on direct CI-to-Business Service relationships via cmdb_rel_ci, just to keep it simple and testable. I haven’t incorporated CI Groups or Application Services yet, but I agree that expanding toward a full CSDM model would make this more robust. I appreciate you remarks and revisit it once the base functionality is validated.
I’ll mark this as a potential enhancement . Thank you.

if (bs.get(rel.parent.toString())) {
result.businessServiceId = bs.getUniqueValue();
result.businessServiceName = bs.getDisplayValue();

} else {
gs.log('No Business Service relationship found for CI: ' + ciSysId);
result.businessService = 'No Business Service linked';
}

}

return JSON.stringify(result);
},

});


/**onChange Client Script on Change_Request form when CI changes */

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ga = new GlideAjax('GetServiceDetails');
ga.addParam('sysparm_name', 'getService');
ga.addParam('sysparm_ci_sys_id', newValue);
ga.getXML(callScriptInclude);

function callScriptInclude(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not handle the response. The description says it will filters business services (line 6 of the description). This is not done in this script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Willem,
My apologies, I missed to handle the response . This has been corrected.

}

}
Loading