new Workflow().restartWorkflow(current, true) does not maintain a state of Approvals

Makosko
Tera Expert

Hello Gurus,

According to SNOW documentation for the restartWorkflow of the Workflow class, listed below:

* If maintainStateFlag is true, then all approvals and tasks will maintain

      * their state. This is used when you want to recalculate the approvals and

      * tasks for a workflow by only adding new approvals and tasks that are required

      * without impacting the current approvals and tasks. (An example of when this

      * would be used is when adding an affected company to a change request. In this

      * case, we want to recalc the approvals so that the new affected company is

      * added as an approver, but none of the existing approvals are affected in any

      * way - that is, we do not want to reset all of the approval processing, we

      * just want to add the one new affected company approval.)

states of existing Approvals should not be changed. However, when my workflow is reset using this script, Approved approvals are reset back to "Requested".

Any idea why that is happening and any possible workarounds ?

My business rule, which resets a workflow as follows:

(function(){

    var comment = 'Workflow Restarted owing to the Approval Field changing from Rejected to Requested';

    var gLock = new GlideRecordLock(current);

                gLock.setSpinWait(50);

      if (gLock.get()) {

                new Workflow().restartWorkflow(current, true);

                current.setDisplayValue('approval_history', comment);

      }

})()

Cheers

Maros

2 REPLIES 2

PeterWiles
Kilo Sage

If the approvals are created in the workflow via the approval tasks, then restarting the workflow will reset these approvals. It's how the workflows work.



If you don't want these to be reset, then I think you need to run a script to create the approvals instead of using the approval tasks. Then there is a workflow task that can wait for manual approvals.


Peter,



approvals are created using standard User/Group Approval activities. Restarting the workflow using the method mentioned previously should leave Approval records in their current state if the maintainstateflag is set to TRUE ( second parameter )...



Cheers


Maros