In the last post, Terminate Site Workflows with Nintex – Part 1, we went through the process of identifying the HTML markup and data elements under the covers necessary to terminate site workflows through Nintex. In this article, we will build the Nintex site workflow to perform the operation.
From the previous post, you’ll remember that we need 4 pieces of information to terminate a site workflow:
- Form Action Parameter: Workflow Instance ID
- Form Field: __EVENTTARGET
- Form Field: __EVENTARGUMENT
- Form Field: __REQUESTDIGEST
Also, from the previous post, we saw that we already have 2 form fields already: __EVENTTARGET, which has a static value of ctl00$PlaceHolderMain_HtmlAnchorEnd and __EVENTARGUMENT, which is blank. So the only dynamic values we need to extract through the Nintex process are: Workflow Instance ID and __REQUESTDIGEST.
With all of these values, the Nintex workflow is not that complex and ends up being fairly small with the following logic:
- Extract all of the Workflow Instance IDs of the workflows with the status of “Error Occurred”.
- For each Workflow Instance ID:
- Extract Request Digest Information
- Call Web Request Action to terminate the workflow
Set up workflow variables
Whenever possible, I like to set up my workflow variables in advance. Here are the variables needed for the workflow:
Variable Name | Type | Description |
vWorkflowListMarkup | Multiple lines of text | Holds HTML markup for the Site Workflows page |
colWFInstances | Collection | Holds all of the Workflow Instance markup snippets from which the Workflow Instance ID will be extracted |
vWFInstance | Single line of text | Holds a single item from colWFInstances |
cntColWFInstances | Integer | Count of items in colWFInstances |
colWFInstanceIDs | Collection | Holds the single-item collection of the extracted Workflow Instance ID |
vWFInstanceID | Single line of text | Holds the single item from colWFInstanceIDs |
vWorkflowInstanceMarkup | Multiple lines of text | Holds HTML Markup of Workflow Instance Page (clicking on the workflow instance from the Site Workflows page) |
colRequestDigests | Collection | Holds the single-item collection of the Request Digest from the Workflow Instance Page. |
vRequestDigest | Single line of text | Holds the single item from colRequestDigests |
Extract Workflow Instance IDs
- Start a new Site Workflow
-
Add a Web Request Action to pull the markup for the Site Workflows Page
We first need to get the markup for all the “Site Workflows” page so that we can extract all of the “Error Ocurred” workflow links.
To do this, drag a Web Request Action onto the Nintex canvas and configure it with the following field values:
URL: <Web URL>/_layouts/15/workflow.aspx
Username: user with permissions to view the Site Workflows page
Password: their password
Submission Type: POST
Content type: application/x-www-form-urlencoded
Store result in: vWorkflowListMarkup
-
Add a Regular Expression Action to extract all of the Workflow Instance IDs from the page with the status of “Error Occurred”
Configure the action with the following values:
Pattern: WorkflowInstanceID=\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}” title=”Error Occurred”>\s*Error Occurred\s*</a>
Operation: Extract
Input Text: {WorkflowVariable:vWorkflowListMarkup}
Store Result In: colWFInstancesNote: This collection will hold markup from which the WorkflowInstanceID will still need to be extracted.
-
Add a Collection Operation Action to capture the count of Workflow Instance IDs for logging purposes
Configure action with the following values:
Target Collection: colWFInstances
Action: Count
Store Result In: cntColWFInstances
Under the “Common” ribbon item, add an entry logging the value of cntColWFInstances in the “Message to log on Completion” field.
Loop Through all Workflow Instance IDs and Terminate Workflows
The following steps loop through each Workflow Instance ID markup in colWFInstances, extracts the Workflow Instance ID, pulls the markup from the Workflow Instance Page, extracts the Request Digest value, and uses those values to terminate the workflow.
Add a For-Each Logic Control
Configure Logic Control with these values:
Target collection: colWFInstances
Store result in: vWFInstance
Within the For-Each Control on the canvas:
- Add a Regular Express action to extract the Workflow Instance ID
Configure action with these values:
Pattern: \{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}
Operation: Extract
Store result in: colWFInstanceIDs
-
Add a collection operation to pop the single Workflow Instance ID from colWFInstanceIDs
Configure action with the following values:
Target Collection: colWFInstanceIDs
Action: Pop
Store result in: vWFInstanceID
-
Add Web Request action to extract the markup for the Workflow Instance Page
Configure the action with the following values:
URL: <Web URL>/_layouts/15/WrkStat.aspx?WorkflowInstanceID=<vWFInstanceID>
Username: username of user with permissions to view Workflow Instance Page
Password: this user’s password
Action: POST
Content type: application/x-www.form-urlencoded
Store Result In: vWorkflowInstanceMarkup
-
Add a Regular Express Action to extract Request Digest information markup from page markup
Configure action with the following values:
Pattern: id=”__REQUESTDIGEST” value=”.* -0000″ />
Operation: Extract
Input Text: {WorkflowVariable:vWorkflowInstanceMarkup}
Store Result In: colRequestDigests
-
Add a collection operation to pop the single Request Digest markup from colRequestDigests
Configure action with the following values:
Target Collection: colRequestDigests
Action: Pop
Store result in: vRequestDigest
-
Add a Regular Expression action to extract the actual Request Digest from the markup
Configure the action with the following values:
Pattern: 0x.+-0000
Operation: Extract
Input text: {WorkflowVariable:vRequestDigest}
Store result in: colRequestDigests (reusing this variable) -
Add a collection operation to pop the single Request Digest value from colRequestDigests
Configure action with the following values:
Target Collection: colRequestDigests
Action: Pop
Store result in: vRequestDigest (reusing this variable, too) -
Add a “Log in history list” action to print the terminating workflow values (optional)
Configure the action with the following value:
Log Value: Terminating Workflow. Workflow Instance ID: {WorkflowVariable:vWFInstanceID}; Request Digest: {WorkflowVariable:vRequestDigest}
-
Add a Web Request Action to call the post to the form and terminate the workflow
Configure the action with the following values:
URL: <Web URL>/_layouts/15/WrkStat.aspx?WorkflowIntanceID=<vWFInstanceID>
Username: username of user with permission to terminate the workflow
Password: password for user
Action: POST
Content Type: application/x-www-form-urlencoded
Other Values: __EVENTTARGET=ctl00$PlaceHolderMain$HtmlAnchorEnd&__EVENTARGUMENT=&__REQUESTDIGEST={WorkflowVariable:vRequestDigest}
That’s it!
When the workflow is built, it should resemble the following (long) image:
All that’s left is to Publish and Execute!
Running this workflow with our example workflows, we get the following results:
Here’s a link to Download the Terminate Site Workflows Workflow (Rt Click and Save As).
One thought on “Terminate Site Workflows with Nintex Part 2 | SharePoint How-To”