Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Info Message is populated when trying to delete "Primary ci" from affected ci related list

Saranya2
Tera Contributor

Hi All,

-> I have a requirement to update the affected ci related list based on update of "Configuration item" on the change form.

-> I have written before update BR to remove old ci entries based on ci update. but when updating the record it populate the OOTB info message "A task's primary CI cannot be removed from Affected CIs - change or remove the CI from the task form instead"

-> Even I am not trying to delete primary ci which we selected on the change form. But still I am getting this message. I am not sure where I did mistake. Can anyone please help. 

Before Update BR:

prim ci.PNG

 

prim ci 1.PNGaffc ci.PNG

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Have you confirmed in the ci_list log that the array does not contain a task_ci record that contains the previous.cmdb_ci or the current.cmdb_ci? A more straightforward and efficient way to handle the removePreviousCI function would be to use the array in the addQuery like this so that you are only deleting records once:

var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.addQuery('sys_id', 'IN', ci_list.join(','));
rec.query();
while (rec.next()) {
    rec.deleteRecord();
}

If you are certain you are not removing an affected CI record that is the primary cmdb_ci on the Change record then you can add this line before this while loop that deletes records so that no other Business Rules will run

rec.setWorkflow(false);

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Have you confirmed in the ci_list log that the array does not contain a task_ci record that contains the previous.cmdb_ci or the current.cmdb_ci? A more straightforward and efficient way to handle the removePreviousCI function would be to use the array in the addQuery like this so that you are only deleting records once:

var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.addQuery('sys_id', 'IN', ci_list.join(','));
rec.query();
while (rec.next()) {
    rec.deleteRecord();
}

If you are certain you are not removing an affected CI record that is the primary cmdb_ci on the Change record then you can add this line before this while loop that deletes records so that no other Business Rules will run

rec.setWorkflow(false);

 

Hi @Brad Bowman ,

It is working.. Thank You!

You are welcome!