Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

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

Riya Verma
Kilo Sage

Hi @keerthana ,

 

Hope you are doing great.

 

Navigate to "Business Rules" in ServiceNow and create a new one with the following details:

  • Table: Configuration Item [cmdb_ci]
  • When: Before
  • Delete: checked

 

(function executeRule(current, previous /*, gs*/) {
    var relatedIncidents = new GlideRecord("incident");
    relatedIncidents.addQuery("cmdb_ci", current.sys_id);
    relatedIncidents.query();
    
    if (relatedIncidents.hasNext()) {
        gs.addErrorMessage("This Configuration Item is associated with incident records and cannot be deleted.");
        current.setAbortAction(true);
    }
})(current, previous);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

script ok, how to get a output because  didn't open a configuration table