sync CI on Change Task to Affected CI list on Change Request

taddparris
Kilo Expert

We would like to start having the Configuration Item on a Change Task sync to the Affected CI related list on the Change Request.  

If a Change Request's CI was (AAA) and there was a Change Task for (BBB), we want both AAA and BBB to show up in the Affected CI related list.   The best approach appears to have a business rule that will create a new form on the Task_CI table, just having some difficulties doing it.   I took an existing Business Rule "Sync CI with Affected CIs" and made it specific for the Change Task table and made some modifications.   Below is the script and some information about the tables and fields being used.   If the form uses same Task ID as the Change Request, it should show up on the Change Request related list.   Just need help in making sure it is creating that Task_CI record.

Affected CI's Table = Task_CI

Change Request Table = Change_Request

Change Task Table = Change_Task

Business Rule runs on the Change Task Table.

current.cmdb_ci.changes()

if (!previous.cmdb_ci.nil())

    removePreviousCI();

if (!current.cmdb_ci.nil())

    addCurrentCI();

function removePreviousCI() {

    // Delete Affected CI records for this task and previous CI

    var rec = new GlideRecord('task_ci');

    rec.addQuery('change_task.change_request', current.sys_id);

    rec.addQuery('ci_item', previous.cmdb_ci);

    rec.query();

    while (rec.next())

          rec.deleteRecord();

}

function addCurrentCI() {

    //Create Affected CI record for this task and current CI

    var rec = new GlideRecord('task_ci');

    rec.addQuery('change_task.change_requestchange_request', current.sys_id);

    rec.addQuery('ci_item', current.cmdb_ci);

    rec.query();

    if (rec.next())

          return;

    rec.initialize();

    rec.change_task = current.change_request;

    rec.ci_item = current.cmdb_ci;

    rec.insert();

}

Currently I am getting a looped error which looks like this

find_real_file.png

Thank you for any help you can provide

10 REPLIES 10

You are exactly right.   Looks like I need to add an IF statement, if the cmdb_ci matches the Change Request then do not delete the record.   I am not very good at scripting yet so I will have to try out a few things, any suggestions would be great.   Thanks so far for the help, you got me going in the right direction I think.