-
Notifications
You must be signed in to change notification settings - Fork 912
Business Service Fetch when CI changes #1739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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: '' | ||
| }; | ||
|
|
||
| // 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'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| 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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello Willem, |
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.