diff --git a/Server-Side Components/Script Includes/Business Service Fetch When CI Changes/README.md b/Server-Side Components/Script Includes/Business Service Fetch When CI Changes/README.md new file mode 100644 index 0000000000..f23788d6cb --- /dev/null +++ b/Server-Side Components/Script Includes/Business Service Fetch When CI Changes/README.md @@ -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. + diff --git a/Server-Side Components/Script Includes/Business Service Fetch When CI Changes/scriptinclude.js b/Server-Side Components/Script Includes/Business Service Fetch When CI Changes/scriptinclude.js new file mode 100644 index 0000000000..ca017ed9f7 --- /dev/null +++ b/Server-Side Components/Script Includes/Business Service Fetch When CI Changes/scriptinclude.js @@ -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'); + 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"); + } + +}