diff --git a/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/beforeBusinessRule.js b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/beforeBusinessRule.js new file mode 100644 index 0000000000..80db0bfaa1 --- /dev/null +++ b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/beforeBusinessRule.js @@ -0,0 +1,7 @@ +(function executeRule(current, previous /*null when async*/) { + + // Call the Script Include + var populator = new DynamicFieldPopulator(); + populator.populateFields(current, current.getTableName()); + +})(current, previous); diff --git a/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/readme.md b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/readme.md new file mode 100644 index 0000000000..ec9f7b772c --- /dev/null +++ b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/readme.md @@ -0,0 +1,16 @@ +Project Description + +Dynamic Field Population from CMDB is a reusable ServiceNow solution that automatically fills key fields on incidents, tasks, or change requests based on the selected Configuration Item (CI). By fetching data such as Owner, Assignment Group, Location, Department, and Business Service directly from the CMDB, this project reduces manual effort, ensures data consistency, and improves ITSM efficiency. + +It leverages a Business Rule that triggers on record insert or update, combined with a Script Include that handles dynamic mapping of CI fields to target fields. The solution can be extended for multiple tables, integrated with the Service Portal via GlideAjax, and configured using a JSON or mapping table for maximum flexibility. + +Key Benefits: + +Saves time for agents by auto-filling fields. + +Reduces errors and ensures standardized data. + +Reusable across multiple tables (Incident, Change, Problem). + +Easily configurable for different CI-to-field mappings. + diff --git a/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/scriptinclude.js b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/scriptinclude.js new file mode 100644 index 0000000000..da1dc2e7e5 --- /dev/null +++ b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/scriptinclude.js @@ -0,0 +1,33 @@ +var DynamicFieldPopulator = Class.create(); +DynamicFieldPopulator.prototype = Object.extendsObject(AbstractAjaxProcessor, { + + populateFields: function(currentRecord, tableName) { + + // Ensure CI is selected + if (!currentRecord.cmdb_ci) return; + + // Fetch CI record + var ciGR = new GlideRecord('cmdb_ci'); + if (!ciGR.get(currentRecord.cmdb_ci)) return; + + // Mapping: CI field -> Target record field + var mapping = { + "owned_by": "assigned_to", + "assignment_group": "assignment_group", + "location": "location", + "department": "u_department", // custom field example + "business_service": "cmdb_ci_service" + }; + + // Loop through mapping and populate fields if empty + for (var ciField in mapping) { + var targetField = mapping[ciField]; + if (!currentRecord[targetField] || currentRecord[targetField] == '') { + currentRecord[targetField] = ciGR.getValue(ciField); + } + } + + return currentRecord; // optional, for reusability + } + +});