If SLA definition is related to a catalog item when user clicks delete ui action don't allow delete

Luke James
Tera Contributor

Hello All, 

 

I have a requirement where the client needs a way when the admin user clicks the delete button on a SLA Definition, that is related to a Catalog item, it displays a warning message. 

 

Anyone have any idea on how this could be done? How can you check that the SLA definition is related to a catalog item? 

 

Kind Regards, 

 

Luke

3 REPLIES 3

James Chun
Kilo Patron

Hi @Luke James,

 

You would create an SLA Definition against a Task or its extended tables such as Incident, Requested Item, etc, but not against a Catalog Item.

 

If you are referring to a specific catalog item(s), you can use the SLA definition's condition field, but if not, I would simply look at SLA Definitions that are built against the [sc_req_item], [sc_request], and [sc_task] tables.

 

Cheers

 

Thanks for your response @James Chun . Essentially we have created a field called u_sla on the sc_cat_item table. The u_sla field is populated with an Sla definition. What I need is when an admin clicks on delete of the sla definition, for the ui action to check if that sla definition is in the u_sla field on any catalog item? Any thoughts?

@Luke James,

 

You will have to override an OOB Delete UI Action.

Create a new UI Action something like the one below 

JamesChun_0-1718310500651.png

Then create a Business Rule that checks if the current SLA definition has associated Catalog item.

e.g.

JamesChun_1-1718310572940.png

 

Script:

(function executeRule(current, previous /*null when async*/ ) {

    //Query catalog items to see if current SLA Definition is associated with any of them
    var catGr = new GlideAggregate('sc_cat_item');
    catGr.addEncodedQuery('u_sla=' + current.getUniqueValue() + '^active=true');
    catGr.addAggregate('COUNT');
    catGr.query();
    if (catGr.next()) {
        if (catGr.getAggregate('COUNT') > 0) {
            g_scratchpad.prompt_delete = true;

        } else {
            g_scratchpad.prompt_delete = false;

        }
    }

})(current, previous);

 

You may need to adjust the scripts a bit to meet your requirements.

Note that this is for the form UI Action only, you may want to consider adding the same functionality for the deletion from the list view. Also consider when a SLA Definition is deactivated, rather than a deletion.