using set abort action

keerthana
Tera Contributor

if user try to delete the any config item , if that particular item is associated with any other records like incident means , it should abort the delete action.

6 REPLIES 6

Peter Bodelier
Giga Sage

To start with... I would discourage deleting Config items at all. Use install/operational status to maintain your data.

 

That being said, you will need a delete Business Rule, with script to lookup any relations in the cmdb_rel_ci table. If they exist abort the action.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

AnubhavRitolia
Mega Sage
Mega Sage

Hi @keerthana 

 

You can write below Delete Business Rule on CMDB table:

 

var tsk = new GlideRecord('task');
tsk.addQuery('cmdb_ci', current);
tsk.query();

if(tsk.hasNext())
{
current.setAbortAction(true);
}

 

This will check if any Task based record like Incident, Problem, Change, etc is having current CMDB CI, than it will abort action.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Utpal Dutta
Tera Guru

Hi Keerthana,

If your configs are stored in a table then you can always use Delete business rule for this kind of requirement. Delete BR will only run when a user tries to delete the record from that table. 

So, you need to write script in Delete BR that will Glide Record and check Incident table for a specific field where it can find that confing written. If it is found then abort the action else let the user delete the record.

You may have to write multiple Glide Record queries if you want to check multiple tables. I'm writing a sample script for your Delete BR below:

 

var grInc = new GlideRecord('incident');
grInc.addQuery('Your Config Field which is there on Incident' , current.YOUR_CONFIG_FIELD_ON_CURRENT_TABLE);
grInc.query();

if(grInc.hasNext()){
current.setAbortAction(true);
}

 

If my answer helps then please mark it Helpful or Correct!

 

Thanks,

Utpal

how to check a output