sub workflows and approvals

poyntzj
Kilo Sage

Hi all

I am working on an approval process to give us flexibility and to use the same approval code over and over again for ease.

Initial tests are all good, but now at the next test I have an issue

 

I have a workflow - "Run Approvals".

It will grab data passed to it via script into the scratchpad and then run the approvals.

This is fine until I call it a second time

 

I have a workflow

It sets the details into the scratchpad and call "Run Approvals" as a sub workflow (see below)

Approvals are sent and updated and ultimately approved. - all is good.

The next phase is to set more details into a new scratchpad and call "Run Approvals" again

It now removed ALL the old approvals and creates a new set.

 

Creating a new set is correct, but I need to keep the old approvals there too.

I cannot workout if this is a Script Include or a Business Rule on one of the "wf_" tables.

 

Does anyone have a better idea than me of what mechanism is being used when this happens.

The errors when you run this process this way is

  • Approvals have been reset

On taking this I did think it was the Script Include, but by skipping the whole of the section in the WorkflowApprovalUtils it still cleared the old approvals.

 

I may also need to run the "Run Approvals" in parallel which it can do with different Scratchpads, but when I do this one of the workflows is run and adds its approvers, then the other one then kicks in, removes the approvers and leaves just its approvers there.

This time the error messages are (the approval process here is looking for where it need just one approval from the group, hence the rule One of.)

  • Group approval for KIN Emergency IT deleted since it no longer matches approval rule One of.  
  • Group approval for KIN EMEA MMS IT deleted since it no longer matches approval rule One of.

 

Run Approvals.png

approval workflow.png

1 ACCEPTED SOLUTION

poyntzj
Kilo Sage

After a lot of hunting down, I did see a message on here (lost the link now) that mentioned "Workflow Activity Definitions".


I headed in there there and there is one called "Approval - Group"


Looking at it, I can see it removes some approvals if there is a difference in ID's, of which mine will be as they are different workflows


I added a small section that looks at the wf_context for the current record that searches for my "Run Approvals" workflow


It there are NO matches, it will then delete as per normal


If there are matches, it skips the step and the approvals are left alone.



Cheers


View solution in original post

6 REPLIES 6

Dominik Simunek
Tera Guru

Hi,



I have same problem that once the Approval - User activity is executed for the second time, the old Approvals are deleted from the system. After my investigation I have realized that this is coded in the Workflow Activity definition. There is function "_checkDroppedApprovals" which is called during the execution of the activity. The description of the function is "Delete any approvals that we previously created but did not match during this creation pass".



I have tested little bit on demo instance how this could be resolved. Firstly I have tried to basically remove the deletion code (comment or remove the row with gr.deleteRecord() in the function) in the OOTB activity definition and this looks working. Approvals are not deleted anymore and new ones are created. It even looks that the approval strategy is working correctly so that if you update (approve/reject) an old one approval this does not affect the current activity execution. Only once you approve a new approval the activity execution is completed.



Unfortunately I would not like to customize OOTB workflow activity definition since it can be used by other workflows as well and the OOTB activity should be still available. So I have tried to copy the existing activity definition with all variables, conditions and UI policies and customize this newly created activitiy definition, but this does not work for me. From some reason the activity is skipped - not sure why.



But generally I think that it should work - copy existing Approval - User activity and customize it in the way that deletion part will be omitted and use this new activity within the workflow which is cycled and where the same approval activity is executed multiple times.



Other option could be to use Run Script activity instead of Approval activity and create approvals within a script and handle approved/rejected decision on your own.


Hi Dooma


It is what I found too. I don't want to amend OOTB functionality if I can help it, with Script includes I copy the OOTB one, rename and switch to the new one.


With this I could not find a way to do it, but as I want it to delete the approvals in all but 1 circumstance



I add this at line 252 so it will only exclude if the running workflow is my "Run Approvals".   If it does not match, run the existing deletion



          var gr = new GlideRecord('wf_context');


         


          gr.addQuery('table', 'change_request');


          gr.addQuery('state', 'executing');


          gr.addQuery('id', current.sys_id);


          gr.addQuery('workflow','82f465dc6f8351007e874c871e3ee401')


          gr.query();


         


          if (!gr.next())