gs.setRedirect() in combination with current.setAbortAction(true) not executed (Before/Update BusinessRule)

Meloper
Kilo Sage

Hi,

if a Problem has an active ProblemTask or an active attached Incident, it should not been closed.

I use an on before BR.

current.setAbortAction works but the Form does not reload.

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

    //Check for active Problem Tasks of Current Problem
    var grPTASK = new GlideRecord("problem_task");
    grPTASK.addQuery("problem", current.sys_id);
    grPTASK.addQuery("active", true);
    grPTASK.query();
    if (grPTASK.hasNext()) {

        current.setAbortAction(true);
        gs.addErrorMessage('Anzahl der Problems gleich' + grPTASK.getRowCount());
        gs.addErrorMessage('Anzahl der current state gleich' + current.state.getDisplayValue());
        gs.addErrorMessage('Anzahl der previous state gleich' + previous.state.getDisplayValue());

        current.state = previous.state;
        gs.setRedirectURL(current);

    } else {
        var grINC = new GlideRecord("incident");
        grINC.addQuery("problem_id", current.sys_id);
        grINC.addQuery("active", true);
        grINC.query();
        if (grINC.hasNext()) {

            current.setAbortAction(true);
            gs.addErrorMessage('Anzahl der Incidents gleich' + grINC.getRowCount());

            current.state = previous.state;
            gs.setRedirectURL(current);
        }
    }



gs.setRedirectURL(current);
})(current, previous);

 

I found many unsolved Question and this KB/Problem:

https://hi.service-now.com/kb_view.do?sysparm_article=KB0539962

We also use some BR with this commands and it works....

 

So i need a refresh of the Form after the action aborted.

What should i do?

 

Currently it behaves like this:
The Action aborted and the new Values are on the form. User has to refresh and the Record appears with the previous Values. 

 

But i don#t want that the user has do refresh manually.

 

11 REPLIES 11

Angel Ram_rez1
Kilo Contributor

There is a known issue about this subject, cannot execute redirect when setabortaction(false):

https://hi.service-now.com/kb_view.do?sysparm_article=KB0539962

Derek Sewall
Tera Expert

Looks like this is a known bug, KB0539962. I did find a workaround that seems to be working for me within a BR:

 

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

current.setAbortAction(true);
var table = current.getTableName();
var sysId = current.getUniqueValue();
var newUrl = table + '.do?sys_id=' + sysId;
gs.setRedirect(newUrl);

})(current, previous);