Ability to upload list of multiple devices for a Change Request to Impacted Services/CI field.

fallond
Kilo Contributor

Often I get CHGs from Infrastructure team that includes many server/device CI's in either attachment or pasted into Long Description. How Can I upload that list to the Impacted Services/CIs tab on a Change Request? Currently have to add them manually(up to 80 or more). I am hoping to tie the CHG# to all the devices for tracking. Thank you

4 REPLIES 4

Medi C
Giga Sage

Hello @fallond,

 

You can align with the infrastructure team on a prefix and a list structure of the comment that can be used to identifiy that this is a list of CIs. Example:

Impacted CIs: SAP Enterprise Services, SAP Enterprise Services, SAP Payroll

 

Then create a business rule which would run "On After" when "Additional Comment" changes or "Work notes" Changes (Depending where the infra team is putting the list)

MediC_0-1743210658322.png

 

In the Script, You can use the following:

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

    var comments = current.comments.getJournalEntry(1).split("\n")[1];

    var services = comments.toString().split("Impacted CIs:")[1].toString().split(",");
    for (var i = 0; i < services.length; i++) {
		var ci = getServiceSysId(services[i].toString().trim())
        if (!isServiceAlreadyAdded(ci, current.sys_id) || !ci) {
            return;
        }

        var grServiceTask = new GlideRecord("task_cmdb_ci_service");
        grServiceTask.initialize();
        grServiceTask.task = current.sys_id;
		grServiceTask.cmdb_ci_service = ci;
		grServiceTask.insert();
    }
})(current, previous);

//Function to check if the CI is already added as an impacted Service/Ci
function isServiceAlreadyAdded(service, taskId) {
    var gaServiceTask = new GlideAggregate("task_cmdb_ci_service");
    gaServiceTask.addQuery("task=" + service + "^cmdb_ci_service.name=" + service);
    gaServiceTask.addAggregate("COUNT");
    gaServiceTask.query();

    if (gaServiceTask.next()) {
        return gaServiceTask.getAggregate("COUNT") == "0";
    }
    return false;
}

//Function to get the Service SysId
function getServiceSysId(ciName) {
    var grCI = new GlideRecord("cmdb_ci");
    if (grCI.get("name", ciName)) {
        return grCI.sys_id;
    }
}

 

Results:

Writing comment on the predefined format:

MediC_1-1743212431682.png

Impacted Services/Cis - Before posting the comment:

MediC_2-1743212461027.png

Impacted Services/Cis - After posting the comment:

MediC_3-1743212503831.png

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Hello @fallond,

 

Was my answer helpful? 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @fallond 

The solution provided by @Medi C is good, but I would suggest that the team manually enter the Service-related list in ServiceNow and establish the relationships. Once that’s done, they can pick the related CI as well. The key is ensuring that the relationship between the Service and the CI exists; the rest of the platform can handle the rest.

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Robert H
Mega Sage

Hello @fallond ,

 

Not specifically what you are asking for, but maybe you can look into "Dynamic CI Groups" to create reusable sets of CIs based on conditions and/or manual selection.

 

I'm also going to assume that the lists that you receive contain the servers/devices on which the changes are made? Because that would actually make them the "Affected CIs". Impacted CIs are typically the services or applications that might get impacted if you make a change on these servers.

 

The basic steps would involve:

  1. Go to Configuration > CMDB Groups and create one or more CMDB Groups. For example, you could have one for "All SAP Servers" or "Servers in location XYZ", etc. Use the related lists "CMDB Group Contains Encoded Queries", or "CMDB Group Contains Configuration Items", or both, to define the CIs that shall be part of the CMDB Group.
    RobertH_0-1743234917664.pngRobertH_1-1743235177500.png
  2. Go to Configuration > Dynamic CI Groups and create one or more Dynamic CI Groups. In their "CMDB Group" field select the CMDB Group that you have created above.
  3. Now you can add these Dynamic CI Groups to the "Affected CIs" list of your Change Request. After a few seconds all the CIs that are contained in that group will be added as well.
    RobertH_2-1743235295308.png

     

Regards,

Robert