Can You Cancel a Pending Workflow Task?


Userlevel 4
Badge +10

Hi Folks,

I have a number of forms that have a cancellation panel on them where a person can cancel the request. Up to now, I have accomplished this by having a separate workflow running waiting for a Cancel field to equal yes, then can el any other running workflows.

I want to find out if there is a way to do this without having a separate workflow running.

 

So, lets suppose there is a flexi task running and someone clicks cancel on the form. How would I exit the pending flexi task and move on with the workflow to run through some other actions?

 

Thanks and Regards,

Patrick


25 replies

Badge +12

@kelliganp ......you can set the workflow to start at item menu.....you can name the workflow as Cancel Request. This will trigger the workflow which will terminate all running workflow. When the workflow which assigns the task gets terminated, it will automatically cancels all the task associated with it.

Userlevel 4
Badge +10

Hi @kunalpatel

Thanks for the reply. The solution you propose is essentially the same thing I already have but it is executed within the form in my solution. You propose a separate workflow that runs to cancel the other(s). My primary workflow still has work to do when a cancellation takes place and the flexi task is aborted. Case and point, lets say I have a leave request that has pulled available time off from a time bank to reserve it for the current request. Upon cancellation, I will want the workflow to abort the flexi task and return any reserved time off back to the requestor's bank of available time off.
Currently, to accomplish this, I must cancel the running primary workflow with a cancellation workflow and then restart the primary workflow to complete the necessary time bank work. I accomplish this with a state machine, switch, and state flags so that when the cancellation takes place, the workflow knows to run through the cancelled state. This works reliably but I am looking for a more elegant way to accomplish this with less overhead. Especially one that does not require an additional workflow and can be handled by the use from within the form.

Any thoughts?

Thanks and Regards,

Patrick

Badge +12

@kelliganp ......What if you use parallel branch? In 1 branch use the task action and get the action ID, in 2nd branch use wait for item update action?

Userlevel 4
Badge +10

Hi @kunalpatel,

I think that you response sparked some thoughts on this but I tried to build a test model and discovered that the Flexi task action will not allow the use of the "Action ID" variable; only a Number or List item ID data type when storing the task ID. Also, the "Complete workflow task" action  which seems like the logical choice for the other parralell branch in my case, will only accept "Action ID" variable data type. Will this process NOT work with a Flexi task? Can you think of another work around?

 

Thanks so much for the assistance.

Patrick

Badge +12

@kelliganp ......Can you try using Request Approval action? It does have the option to store action ID.

Userlevel 4
Badge +10

Hi @kunalpatel,

I will try and model that as a proof of concept but my workflows call for the features that a flexi task has so using a Request Approval action does not work for my purposes.

Regards,

Patrick 

Badge +12

@kelliganp ....Can you tell me the reason for using flexi task? If it's for the reminder then if you use request approval in parallel branch with reminder action then it will achieve the same thing.

Userlevel 4
Badge +10

@kunalpatel ... Flexible / greater than 2 outcomes.

Userlevel 4
Badge +10

I just wanted to bump this up the list a bit so see if anyone out there wants to take a crack at it.

 

@TomaszPoszytek ?

@emha ?

@rhia ?

@cassymfreeman ?

@andrewg ?

@jesse_mchargue 

 

Well, those are most the heavy hitters that have proved genius in the past... Maybe one of you have an idea! Forgive me for calling you out but activity seems low these days on here and I wanted to see if I could stir up the inboxes a bit. :)

 

Userlevel 7
Badge +17

I don't understand what you want to achieve. Is the "Cancel" one of the options to complete a task?

Or is it just the button that user clicks when they don't want to perform any action?

Badge +12

@kelliganp ....well since you want to perform some other logic in your primary workflow, what if you create a seperate workflow just to assign the flexi task? Start this workflow from primary workflow but wait till flexi task w/f is completed. Now if you stop the flexi task workflow then it will cancel the flexi task and your primary workflow will proceed further. You can also send and receive variable information between primary and flexi task workflow. Use that to build logic to process when flexi task is canceled. 

Userlevel 4
Badge +10

Hi @TomaszPoszytek,

Thanks for responding. The objective is to have a process that many can cancel even when only a few have an active task. There are several approval tiers in the process and for an expensive item where special, lengthy, approval routing needs to take place, the process could take several weeks or even months to close.

While one of these flexi tasks are running, suppose the requestor decides he wants to cancel the request... He should be able to open the form, select a cancellation panel, sign and confirm. When this happens, I want to know if there is some creative way, without having addidional separate workflows running, to escape/abort any active flexitask. 

I was thinking a parralel branch might do it as @kunalpatel has suggested earlier but the flexi task does not have an "Action ID" variable like some of the other tasks. I also do not want to abandon the use of a flexitask if possible.

Does that clarify? If not let me know what is unclear and I will try and elaborate more.

 

Thanks and regards,

Patrick

Userlevel 4
Badge +10

Hi @kunalpatel,

Good thinking... That is similar to my current solution that I have been using for nearly ten years. I have 2 workflows. One is the primary work horse and the other (abort workflow) sits and listens for the cancellation field to change. If it is cancelled, the abort kills the main workflow, restarts it and runs the cancellation branch of the main workflow's state machine. I want to do this with a single workflow as I may have dozens of extra workflows running. I am looking for a more economical and elegant way of making this happen.

Thanks and Regards,

Patrick

Userlevel 7
Badge +17

Hi,

 

so what you can do is to use for example that approach with parallel branch, but in the second branch to flexi task use query task list action. I am doing this by adding related item ID to the title, so then I can query tasks list for tasks having ID in title. It's not very pretty but it works.

 

The other solution would be, to use web service action to call SharePoint API, to get all tasks, along with the field "RelatedItems". That field is an array, so first you would need to go through all the items to extract related item ID, and this way to get a list of really related items :P

 

Ex.:

 

<d:RelatedItems>[{"ItemId":206,"WebId":"4852a749-124d-43db-9537-7211335849ff","ListId":"908133d7-6bf2-4361-b2e5-ae9553a8e07d"}]</d:RelatedItems>

 Achieve it using this URL:
{YOUR SITE URL}/_api/lists/getByTitle('Workflow%20Tasks')/items()?$select=Id,RelatedItems

 

Regards,

Tomasz

 

Badge +16

What about using this?

https://help.nintex.com/en-US/sdks/SDK2013/Reference/SOAP/NW_REF_SOAP_ProcessFlexiTaskResponse.htm

Userlevel 7
Badge +17

Looks promising. How would you use it?

Userlevel 7
Badge +17
BTW it says it's obsolete. Now you should use this one: https://help.nintex.com/en-US/sdks/SDK2013/Reference/SOAP/NW_REF_SOAP_ProcessFlexiTaskResponse2.htm
Userlevel 4
Badge +10

Hi@TomaszPoszytek, I am going to try to model the parallel branch solution first. Then try the solution @cassymfreeman offered.

 

Instead of making the title modification, would it so the same thing to use the flexi task's "Store task IDs" feature and run the query list action in the parallel branch by filtering on the list item id from the flexi task variable? If so, what do I need to do to the task list item to make the flexi task abort?

 

Thanks and Regards,

Patrick

Userlevel 4
Badge +10

Hi @cassymfreeman,

 

I am looking at the updated version of the link you posted. Even if the other method described by @TomaszPoszytek is viable, I want to make this process work in principle because it looks like a very useful skill to have. Some questions...

  • Can you tell me how you would apply this?
  • I think I understand the XML and most of the warnings but should I use a web request or a call web service?
  • Will this be a series of actions on a parallel branch as well?
  • I want to escape the flexi task without approving or rejecting per se... should I use the "Other" branch from the flexi task Advanced Options; and if so, do I need to specify "Other" in <nin:outcome></nin:outcome> or can I put in a more meaningful outcome?
  • The help file states "The approver of the task response is determined by the credentials of the user context specified when this method is invoked. If the credentials of the current user context do not match any of the assignees specified by the Flexi task action that created the task item, this method returns ProcessTaskResponseResult.InvalidUser and the task is not updated". What do you think about finding a way to delegate the task to the workflow initiator to overcome that?

 

I hope I did not overwhelm you with questions.

 

Thanks and Regards,

Patrick

 

Userlevel 4
Badge +10

Ok... I tried to model this part where I captured the task ID in the "Store Task ID" variable. It did not work as the variable did not populate until I responded to the task that the flexi task action was exited.

Userlevel 7
Badge +17

That is exactly the reason. This is why I suggested the option with either querying tasks list for items with specific token in title or to query tasks list via SharePoint rest API and then filter out only records having Id of current record under related items.

Userlevel 4
Badge +10

Hi @TomaszPoszytek, I have been workign on this and I was able to get a return with the URL formation you gave me. My web request returned the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://vector.leidos.com/ASP/dev/nintex/_api/">
   <id>00103ac2-af71-4289-8775-bdd8ffe59d05</id>
   <title />
   <updated>2020-01-23T21:36:46Z</updated>
   <entry m:etag="&quot;3&quot;">
      <id>13352afc-ebb0-4bca-9709-0e9d72ffd062</id>
      <category term="SP.Data.Workflow_x0020_TasksListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
      <link rel="edit" href="Web/Lists(guid'c00c8d5a-a195-4b25-81d0-e88152b550bc')/Items(3)" />
      <title />
      <updated>2020-01-23T21:36:46Z</updated>
      <author>
         <name />
      </author>
      <content type="application/xml">
         <m:properties>
            <d:Id m:type="Edm.Int32">3</d:Id>
            <d:RelatedItems m:null="true" />
            <d:ID m:type="Edm.Int32">3</d:ID>
         </m:properties>
      </content>
   </entry>
   <entry m:etag="&quot;1&quot;">
      <id>b2b1bc9e-2ef1-4c7f-a8e6-7dc58fcf8988</id>
      <category term="SP.Data.Workflow_x0020_TasksListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
      <link rel="edit" href="Web/Lists(guid'c00c8d5a-a195-4b25-81d0-e88152b550bc')/Items(4)" />
      <title />
      <updated>2020-01-23T21:36:46Z</updated>
      <author>
         <name />
      </author>
      <content type="application/xml">
         <m:properties>
            <d:Id m:type="Edm.Int32">4</d:Id>
            <d:RelatedItems m:null="true" />
            <d:ID m:type="Edm.Int32">4</d:ID>
         </m:properties>
      </content>
   </entry>
</feed>

How do I use <m:properties><d:Id m:type="Edm.Int32">4</d:Id><d:RelatedItems m:null="true" /> <d:ID m:type="Edm.Int32">4</d:ID></m:properties>? In the case of this specific Item, the task I want to get to is "4" but I am still unclear on how to identify it from the other tasks in the list.

 

It is important to note that when I use this in production, the workflows will have several flexi tasks in them and will run on state machines so a given task may need to run more than once if the user is asked to edit and resubmit his/her request.

 

Thoughts?

Thanks,

Patrick

Userlevel 7
Badge +17

In that example data under <d:RelatedItems m:null="true" /> is null. So it seems that these tasks were not created keeping the relation to original item. If this is the case, that for some reason task generated for your items are not in relation, then either you have to add something identifying to their title and use that to query list, or use the web service @cassymfreeman mentioned, what for on-premise should be the best idea :)

Userlevel 4
Badge +10

Thanks @TomaszPoszytek. Naming might be tricky unless I use some invrementing variable as the tasks can be reused. I put a 5 minute pasue before the web request just to make sure it did not out-run the felxi task as well. I will keep thinking about this but start modeling the @cassymfreeman  suggestion. Could you take a look at my questions to Cassy and see if you have any thoughts? She has not been able to respond yet.

 

Thanks to you both!!

Patrick

Userlevel 4
Badge +10

Hi @TomaszPoszytek and @cassymfreeman,

I am working on Cassy's suggestion and have some results from a test. My screen shots below show what I am trying...

First I have the layout on canvas that I am using.

6263i6338AA3276B7BFDB.png My Web request configuation is as follows...

6264i701B44FA1FC79C7E.png

Note: I put the value 6 in the taskID for testing purposes as that was the anticipated item id of the next task in this site's task list.

Here is the request XML used in the most recent test...

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:nin="http://nintex.com">
   <soap:Header/>
   <soap:Body>
      <nin:ProcessFlexiTaskResponse2>
         <nin:comments>This workflow was aborted due to outside cancellation.</nin:comments>
         <nin:outcome>Approve</nin:outcome>
         <nin:spTaskId>6</nin:spTaskId>
         <nin:taskListName>Workflow Tasks</nin:taskListName>
      </nin:ProcessFlexiTaskResponse2>
   </soap:Body>
</soap:Envelope>

Below is the results when the web request triggered (from verbose logging)

var_HTTPStatus_TXT: 302

var_ResponseHeaders_COL:

X-SharePointHealthScore=0;
SPRequestGuid=e5b02e9f-8841-b0b4-a2b2-c51469340b0b;
request-id=e5b02e9f-8841-b0b4-a2b2-c51469340b0b;
X-FRAME-OPTIONS=SAMEORIGIN;
SPRequestDuration=329;
SPIisLatency=0;
Persistent-Auth=true;
MicrosoftSharePointTeamServices=16.0.0.4936;
X-Content-Type-Options=nosniff;
X-MS-InvokeApp=1;
RequireReadOnly;
Connection=close;
Content-Length=198;
Content-Type=text/html;
charset=UTF-8;Date=Fri, 24 Jan 2020 18:47:33 GMT;
Location=https://vector.leidos.com/ASP/dev/nintex/Lists/Workflow Tasks/AllItems.aspx;
Server=Microsoft-IIS/8.5;
X-Powered-By=ASP.NET;

var_WebRequestOutcome_MLT:

<head>
<title>Document Moved</title>
</head>
 <body><h1>Object Moved</h1>This document may be found
 <a HREF="https://*****.*****.com/ASP/dev/nintex/Lists/Workflow Tasks/AllItems.aspx">here</a>
</body>

After the web request triggered, the flexi task remained in a pending status (Outcome).

Should the web request have updated the flexi taks outcome in my case to Approve?

 

Thanks and Regards,

Patrick

Reply