Creating Outage when a major incident state changes to accepted.

Erhan1
Tera Expert

Hi Everyone

 

I'm currently fighting with a business rule that I am trying to create. What I would like to happen is when a incident is accepted as a major incident, I would like an automatic outage created for that MI. I have it working to a point where the outage is being created, but there are a couple of issues. 

1 ) Duplicate Outage records are being created so each time an incident is accepted as an MI 2 outages are created.
2) The outage task number is not being populated with the incident number.

3) The Outage record is not showing up on the incident (probably related to 2).

here is my current code

(function executeRule(current, previous /*null when async*/ ) {
    
    var newOutage = new GlideRecord('cmdb_ci_outage');
    newOutage.initialize();
    newOutage.u_business_service = current.business_service;
    newOutage.u_application_service = current.u_app_service;
    newOutage.u_technical_service = current.u_tech_service;
    newOutage.type = 'outage';
    newOutage.cmdb_ci = current.cmdb_ci;
    newOutage.short_description = current.short_description + " Outage";
    newOutage.task_number = current.number;

     var outageInsertSuccess = newOutage.insert();

    if (outageInsertSuccess) {
        gs.log("Outage record created with sys_id: " + newOutage.sys_id);

        // If cmdb_ci is populated, create a record in cmdb_outage_ci_mtom
        if (current.cmdb_ci) {
            var outageCI = new GlideRecord('cmdb_outage_ci_mtom');
            outageCI.initialize();
            outageCI.outage = newOutage.sys_id;
            outageCI.cmdb_ci = current.cmdb_ci;
            outageCI.insert();
        }
 
        var taskOutage = new GlideRecord('task_outage');
        taskOutage.initialize();
        taskOutage.task = current.sys_id; 
        taskOutage.outage = newOutage.sys_id;
        var taskOutageInsertSuccess = taskOutage.insert();

        if (taskOutageInsertSuccess) {
            gs.log("Successfully linked outage " + newOutage.sys_id + " to incident " + current.sys_id);
        } else {
            gs.error("Failed to link outage " + newOutage.sys_id + " to incident " + current.sys_id);
        }
    } else {
        gs.error("Failed to create outage record for Incident " + current.number);
    }
})(current, previous);

any help would be greatly appreciated. I am currently on Xanadu Patch 2.

1 ACCEPTED SOLUTION

Erhan1
Tera Expert

I believe I got it working, by adding a bit more logic. If anyone needs any help related to it, you can respond to this thread and i'll gladly share what else i did.

View solution in original post

1 REPLY 1

Erhan1
Tera Expert

I believe I got it working, by adding a bit more logic. If anyone needs any help related to it, you can respond to this thread and i'll gladly share what else i did.