Skip to content

Conversation

@vijaykumar7177
Copy link
Contributor

@vijaykumar7177 vijaykumar7177 commented Oct 18, 2025

PR Description:

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.

Pull Request Checklist

Overview

  • Put an x inside of the square brackets to check each item.
  • I have read and understood the CONTRIBUTING.md guidelines
  • My pull request has a descriptive title that accurately reflects the changes and the description has been filled in above.
  • I've included only files relevant to the changes described in the PR title and description
  • I've created a new branch in my forked repository for this contribution

Code Quality

  • My code is relevant to ServiceNow developers
  • My code snippets expand meaningfully on official ServiceNow documentation (if applicable)
  • I've disclosed use of ES2021 features (if applicable)
  • I've tested my code snippets in a ServiceNow environment (where possible)

Repository Structure Compliance

  • I've placed my code snippet(s) in one of the required top-level categories:
    • Core ServiceNow APIs/
    • Server-Side Components/
    • Client-Side Components/
    • Modern Development/
    • Integration/
    • Specialized Areas/
  • I've used appropriate sub-categories within the top-level categories
  • Each code snippet has its own folder with a descriptive name

Documentation

  • I've included a README.md file for each code snippet
  • The README.md includes:
    • Description of the code snippet functionality
    • Usage instructions or examples
    • Any prerequisites or dependencies
    • (Optional) Screenshots or diagrams if helpful

Restrictions

  • My PR does not include XML exports of ServiceNow records
  • My PR does not contain sensitive information (passwords, API keys, tokens)
  • My PR does not include changes that fall outside the described scope

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.
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
    }

});
(function executeRule(current, previous /*null when async*/) {

    // Call the Script Include
    var populator = new DynamicFieldPopulator();
    populator.populateFields(current, current.getTableName());

})(current, previous);
@rohi-v rohi-v self-assigned this Oct 18, 2025
@github-actions
Copy link

👋 Unassigning @rohi-v due to inactivity (> 60 min without comments/reviews). This PR remains open for other reviewers.

@earlduque earlduque self-assigned this Oct 18, 2025
@earlduque earlduque merged commit 6ec39d4 into ServiceNowDevProgram:main Oct 18, 2025
2 checks passed
@earlduque
Copy link
Contributor

Just FYI, next time we are hoping that you put an X in all of the check boxes, not just the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants