cmdb_ci and task_ci

ryadavalli
Tera Expert

I have a business rule on task_ci (Affected Cis) which upon deleting the CI from affected cis   will throw a message saying you cannot delete if it a primary Ci as well.

But when I try to delete a CI from cmdb_ci, if that ci is a part of an INC, the above business rule is triggered. Why?

12 REPLIES 12

Hi ravali,



It is because before the CI is deleted it tries to delete its relationship. When it comes to 'Affected CI' table and tries to delete related records in it, 'Prevent removal/update of primary CI' BR prevents it from doing so as current.ci_item == current.task.cmdb_ci matches(as CI on the 'Affected CI' record and CI on the parent task i.e. the INC record are same). But as the abort action in the 'Prevent removal/update of primary CI' can only prevent the delete action on the 'Affected CI' table, CI will be deleted.



If you want the CI not to be deleted if there is a related record in 'Affected CI' table then write the below shown Before delete BR on the 'cmdb_ci' table.



When - Before Delete


Order - 50


Script -


function onBefore(current, previous) {


  //This function will be automatically called when this rule is processed.


  var gr = GlideRecord('task_ci');


  gr.addQuery('ci_item',current.sys_id);


  gr.query();


  if(gr.next()){


  gs.addErrorMessage('Cannot delete CI');


  current.setAbortAction(true);


  }


}



Hope this will give you the desired result



Cheers!!



Thanks,


Tanaji


Hi ravali,



If this answers your query, please can you close this by marking correct answer.



Thanks,


Tanaji


Correct answer


Hi ravali,



Can you please mark it by clicking the 'Mark Correct Answer' below the comments.



Thanks,


Tanaji


Hi,



I donnot see "Mark COrrect Answer" in here !