Prevent incident from being closed if Playbook is running with open activities.

AdamShiner
Tera Guru

Hi All,

I am looking for a way to prevent an incident from being closed if there are activities still open on the playbook.

AdamShiner_0-1747731245118.png

In this Incident I have activities still open that I want to ensure the SD follow. As you can see I am able to resolve this incident whilst these remain open. I have not found a way to prevent the incident from being closed. I did ask my good friend co-pilot which did provide a business rule to create but I have not had much success with it.

AdamShiner_2-1747731363567.png

 

BR:

AdamShiner_0-1747737092908.png

 

 

Has anyone been able to achieve this ?

 

1 ACCEPTED SOLUTION

AdamShiner
Tera Guru

Update: I now have this working using the following BR for anyone else trying to achieve the same result.

 

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord('sys_pd_context'); // Replace with your actual table name
    gr.addQuery('input_table', 'incident');
	gr.addQuery('input_record', current.sys_id);
    gr.addQuery('state', '!=', 'Complete'); // Adjust based on your state values
    gr.query();

    if (gr.hasNext()) {
        gs.addErrorMessage('Cannot close the incident while there are open playbook activities.');
        current.setAbortAction(true);
    }
})(current, previous);

 

View solution in original post

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Hi @AdamShiner 

only having the script is not enough to understand whether you BR is working or not. How have you configured the BR?

Maik

Update the post with the BR, apologies.

AdamShiner
Tera Guru

Update: I now have this working using the following BR for anyone else trying to achieve the same result.

 

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord('sys_pd_context'); // Replace with your actual table name
    gr.addQuery('input_table', 'incident');
	gr.addQuery('input_record', current.sys_id);
    gr.addQuery('state', '!=', 'Complete'); // Adjust based on your state values
    gr.query();

    if (gr.hasNext()) {
        gs.addErrorMessage('Cannot close the incident while there are open playbook activities.');
        current.setAbortAction(true);
    }
})(current, previous);