From 2674449b8d5bd757cf84530851339ef9bc37832b Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 17:26:41 +0530 Subject: [PATCH 1/5] Create readme.md 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. This project is ideal for ITSM teams, ServiceNow developers, and Hacktoberfest contributors who want a lightweight, practical automation solution. --- .../readme.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Server-Side Components/Business Rules/Dynamic Field Population from CMDB/readme.md 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..f703a7ca8d --- /dev/null +++ b/Server-Side Components/Business Rules/Dynamic Field Population from CMDB/readme.md @@ -0,0 +1,17 @@ +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. + +This project is ideal for ITSM teams, ServiceNow developers, and Hacktoberfest contributors who want a lightweight, practical automation solution. From 960ea81599a5fb9662cbdd02c90e1ba866aed7b6 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 17:27:05 +0530 Subject: [PATCH 2/5] Update readme.md --- .../Business Rules/Dynamic Field Population from CMDB/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index f703a7ca8d..a04a0cec63 100644 --- 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 @@ -14,4 +14,4 @@ Reusable across multiple tables (Incident, Change, Problem). Easily configurable for different CI-to-field mappings. -This project is ideal for ITSM teams, ServiceNow developers, and Hacktoberfest contributors who want a lightweight, practical automation solution. +T From 3b0b90fee0d91e6239666847da94a34c38a0e77f Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 17:27:17 +0530 Subject: [PATCH 3/5] Update readme.md --- .../Business Rules/Dynamic Field Population from CMDB/readme.md | 1 - 1 file changed, 1 deletion(-) 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 index a04a0cec63..ec9f7b772c 100644 --- 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 @@ -14,4 +14,3 @@ Reusable across multiple tables (Incident, Change, Problem). Easily configurable for different CI-to-field mappings. -T From 1a74789cfea94ef2c904187aaf858942731a7cc1 Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 17:28:20 +0530 Subject: [PATCH 4/5] Create scriptinclude.js 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 } }); --- .../scriptinclude.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Server-Side Components/Business Rules/Dynamic Field Population from CMDB/scriptinclude.js 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 + } + +}); From 304dacbf27d8c71249c5ace1202d41b993f1224e Mon Sep 17 00:00:00 2001 From: vijaykumar7177 <68215714+vijaykumar7177@users.noreply.github.com> Date: Sat, 18 Oct 2025 17:29:01 +0530 Subject: [PATCH 5/5] Create beforeBusinessRule.js (function executeRule(current, previous /*null when async*/) { // Call the Script Include var populator = new DynamicFieldPopulator(); populator.populateFields(current, current.getTableName()); })(current, previous); --- .../beforeBusinessRule.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Server-Side Components/Business Rules/Dynamic Field Population from CMDB/beforeBusinessRule.js 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);