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

btw can you change the BR as onAfter instead of onBefore?


randrews
Tera Guru

just out of curiosity why not just remove the ci field from the ctask form.. and she the parent ci as a read only field... this way there is no need for scripting to synch them....



for that matter if you are going to require the task ci to be the same as the change form.. why have the ci on the task form at all??



now to throw you a curve ball.. what if they are for example making a modification to an app that has three servers.. and they want to create a task for each servier.... in this case the task ci's should reflect the CI they are working on.. <the app server, db server, or web server> not the application ci itself.


Actually what we want is to allow the Change Task CI to be different than the Change Request.   Because the way ServiceNow designed this application, a Change Request must have a Configuration Item.   They state that all additional CI's being changed or affected should follow the Bulk CI best practice plugin.



The example below is a change that lets say is moving two applications from a server so it affects three CI's   If there is a Change Task with one of those CI's then it should be included in the Affected CI list on the RFC form.



Change Request CI
find_real_file.png


Change Tasks


find_real_file.png


Affected CI list on the Change Request Form


find_real_file.png


ok the affected ci's are stored on a table called affected ci's<task_ci>



Big picture what you want to do is



  • when a change task is inserted or updated and the ci_item   changes
  • check the parent <change> record ci to see if they are same... and check the task_ci table for any entries where the task is the parent and the ci is the same as the current task_ci
  • if you don't find the ci on the parent.. AND you don't find any entries on the task ci table with the same parent and same ci you want to create a new entry on the task_ci table with the task set to the parent.. and the ci set to the current ci.

Sorry i am slow today.



ok on this line 10



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



we are querying the task_ci table   unless your table is different than ours.. the column you want to look at is simply called "task"



I believe you are going to have the same issue on line 20