Skip to content

Commit 6ec39d4

Browse files
Dynamic Field Population from CMDB (#2260)
1 parent 04050bf commit 6ec39d4

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// Call the Script Include
4+
var populator = new DynamicFieldPopulator();
5+
populator.populateFields(current, current.getTableName());
6+
7+
})(current, previous);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Project Description
2+
3+
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.
4+
5+
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.
6+
7+
Key Benefits:
8+
9+
Saves time for agents by auto-filling fields.
10+
11+
Reduces errors and ensures standardized data.
12+
13+
Reusable across multiple tables (Incident, Change, Problem).
14+
15+
Easily configurable for different CI-to-field mappings.
16+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var DynamicFieldPopulator = Class.create();
2+
DynamicFieldPopulator.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
4+
populateFields: function(currentRecord, tableName) {
5+
6+
// Ensure CI is selected
7+
if (!currentRecord.cmdb_ci) return;
8+
9+
// Fetch CI record
10+
var ciGR = new GlideRecord('cmdb_ci');
11+
if (!ciGR.get(currentRecord.cmdb_ci)) return;
12+
13+
// Mapping: CI field -> Target record field
14+
var mapping = {
15+
"owned_by": "assigned_to",
16+
"assignment_group": "assignment_group",
17+
"location": "location",
18+
"department": "u_department", // custom field example
19+
"business_service": "cmdb_ci_service"
20+
};
21+
22+
// Loop through mapping and populate fields if empty
23+
for (var ciField in mapping) {
24+
var targetField = mapping[ciField];
25+
if (!currentRecord[targetField] || currentRecord[targetField] == '') {
26+
currentRecord[targetField] = ciGR.getValue(ciField);
27+
}
28+
}
29+
30+
return currentRecord; // optional, for reusability
31+
}
32+
33+
});

0 commit comments

Comments
 (0)