logo

NJP

Workflow utility "Approval - User" stalls on state "No Longer Required" [Workaround]

Import · Jul 12, 2020 · article

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

Workflow Editor is a legacy product to maintain existing workflows already in production. For new use cases and workflows, use ServiceNow Workflow Studio. Workflow Studio is a low-code alternative to Workflow Editor.

Hi there,

When working with Workflows and Approvals, the majority of the states used for the Approvals will be "Approved" or "Rejected". In some rare cases, "No Longer Required" could apply. Did you also encounter, that when applying the "No Longer Required" state the "Approval - Group" activity does go on while the "Approval - User" workflow activity stalls?

This is an out-of-the-box issue (also still valid in Orlando). After some investigation, I came up with a small and low impact workaround.

Approval - User

To explain our case, let's set up a minor Workflow. A Workflow only containing an "Approval - User" utility.

image

While triggering this workflow (for example with a Catalog Item), an Approval record will be created. When you would simply approve or reject the generated Approval record, the Workflow proceeds. Though, when changing the state to "No Longer Required"…

image

Upon performing a "Nudge" on the Workflow context, the Workflow does proceed.

Business Rule

While investigating this issue, I quickly encountered that this issue does not exist for the "Approval - Group" Workflow activity. Immediate thoughts going to the actual code of both Workflow activities, and also server side script like Business Rules.

Diving into Business Rules and looking at the Conditions, pretty quickly one Business Rule stands out concerning Group Approvals: "SNC - Match state to approval". While testing, and deactivating this Business Rule, also the Group Approval does not proceed anymore.

Workaround

The code used within the Group Approval Business Rule is not what we are after for fixing the User Approval. Though, it does tell us to handle this server-side, for example with a Business Rule. Also we already noticed, that when nudging the Workflow context, the Workflow does proceed.

So, let's set up an after update Business Rule which nudges the workflow.

_When to run_When: afterUpdate: true

Filter Conditions: State | changes to | No Longer Required

Script

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

    var wf = new Workflow();
    var ri = new GlideRecord(current.getValue('source_table'));

    if(ri.get(current.getValue('sysapproval'))) {
        wf.runFlows(ri, 'update');
    }

})(current, previous);

Result

After triggering our Workflow once again, and manually changing the state of the Approval to "No Longer Required"… the Workflow now proceeds immediately image

---

And that's it actually. Hope you like it. If any questions or remarks, let me know!

Kind regards,

Mark Roethof

ServiceNow Technical Consultant @ Quint Technology

1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

image

View original source

https://www.servicenow.com/community/developer-articles/workflow-utility-quot-approval-user-quot-stalls-on-state-quot-no/ta-p/2307266