SCCM Integration - Asset CI Hardware State Mapping

giat
Tera Contributor

For SCCM discovery data - it is populated on the CI table. 

I want the "assign to" to reflect the discovery data in the CI and hardware table.

Is there a way to automate state from "in transit" to "in use" and populate the "assign to" in both table when SCCM discovery is updated?

 

1 REPLY 1

SwarnadeepNandy
Mega Sage

Hello @giat,

One possible way to automate the state and assign to fields based on SCCM discovery data in ServiceNow is to use a business rule script that runs on the cmdb_ci and alm_hardware tables. The script can check if the SCCM discovery data has changed for a CI or hardware record, and if so, update the state to “in use” and assign to the user that is associated with the SCCM data.

Here is an example of how you can write such a script:

  • Name: Update State and Assign To based on SCCM Discovery Data
  • Table: cmdb_ci, alm_hardware
  • When: after
  • Insert: true
  • Update: true
  • Filter conditions: SCCM Discovery Data changes
  • Script: 

 

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

    // Get the SCCM discovery data from the current record 
    var sccmData = current.u_sccm_discovery_data;

    // Check if the SCCM discovery data is not empty 
    if (sccmData) {
        // Parse the SCCM discovery data as a JSON object var sccmObj = JSON.parse(sccmData);
        // Get the user name from the SCCM discovery data
        var userName = sccmObj.UserName;

        // Check if the user name is not empty
        if (userName) {
            // Query the sys_user table to find the matching user record
            var user = new GlideRecord('sys_user');
            user.addQuery('user_name', userName);
            user.query();

            // Check if the user record exists
            if (user.next()) {
                // Get the user sys_id
                var userId = user.sys_id;

                // Update the state to "in use"
                current.state = "in use";

                // Update the assign to field with the user sys_id
                current.assigned_to = userId;

                // Update the current record
                current.update();
            }
        }
    }

} (current, previous);

 

This script will run whenever a CI or hardware record is inserted or updated, and will check if the SCCM discovery data has changed. If so, it will update the state and assign to fields accordingly. You can modify the script according to your needs.

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy