TOPIC
How can you start a workflow using the Call Web Service action?INSTRUCTIONS
Using the StartWorkflow web service method
This first section will demonstrate how to use the StartWorkflow web service within a Call Web Service workflow action, this is an example of a workflow action, not a step-by-step workflow tutorial. The StartWorkflow web service starts a workflow on an item in a document library, where the file URL of the document is known.
Note: This section demonstrates how to configure a Call web service action and is not part of a workflow.
- Open a Call web service workflow action on the design canvas.
- In the URL field, select the Insert Reference icon.
- In the Common tab, select Web URL. Click Ok.
- After the Web URL, type “/_vti_bin/NintexWorkflow/Workflow.asmx” to complete the path to the web service.
- Enter the appropriate credentials for the URL.
- In the Web method field, click the Refresh button and select the StartWorkflow method.
- Enter the Web service output parameters for the Web service message.
-
-
- fileURL (string) – The URL of the document.
- workflowName (string) – The name of the workflow to start. This has been published on the target document library.
- associationData (string) – This parameter is used to pass start data to the workflow (values that can be used to set variables to certain values when the workflow starts).
-
Note: This field may be left blank as there is no start data.
Using the StartWorkflowOnListItem web service method
The StartWorkflowOnListItem web service method should be used if a workflow needs to be started on a list item directly or the item URL is not known.
This Call Web Service action can then be added to any other workflow in your SharePoint site to start the selected workflow; in my example I will use a workflow titled testworkflow01.
We will configure the Call web service action as in the previous section and instead select StartWorkflowOnListItem as the web service method.
- In the URL field, select the Insert Reference icon.
- In the Common tab, select Web URL. Click Ok.
- After the Web URL, type “_vti_bin/NintexWorkflow/Workflow.asmx” to complete the path to the web service.
- Enter the appropriate credentials for the URL entered.
- In the Web method field, click Refresh and select the StartWorkflowOnListItem method.
- Complete the following Web service input parameters.
-
-
- itemID (int) – Contains the ID of the item the workflow will start on.
- listName (string) – The name of the list where the workflow will start.
- workflowName (string) – The name of the workflow to start. This is published on the target list or document library.
- associationData (string) – This parameter is used to pass start data to the workflow (values that can be used to set variables to certain values when the workflow starts).
-
Note: This field may be left blank as there is no start data.
Example of filling in the Web Service input parameters:
The workflow I am using is called Testworkflow01 and the list is in the image below.
I want to start a workflow on this item so I would configure the Web service message as:
-
-
- itemID: 1
- listName: testdoc library
- workflowName: testworkflow01
-
Click Save.
Passing variable values between workflows (using Start Data)
We now know how to configure the Call Web Service workflow action with two different web methods. Another requirement may be to pass certain workflow variables between workflows when they are part of a larger process.
To do this, we must populate the target workflow with start data. These start data variables can then automatically be populated when the workflow is started. The first step is to create a simple workflow with start data configured.
Create a New Workflow
- In the Ribbon, select Workflow Settings and then Variables.
- Click New.
- In the Name field, type “Texta” and select Single line of text as the type.
- Check the Show on start form box and click Save.
- Create a second variable called ‘Number1’ and select Number as the variable type.
- Check the Show on start form box and click Save.
Add a Log in History List workflow action
A Log in History List workflow action can be added to the workflow to log the values of these variables and test whether they were correctly set.
- Drag a Log in History List action to the design canvas and double-click on the action to open the configuration dialog.
- In the text box, type “Text =” and then click on the Insert Reference icon.
- In the Workflow Variables list, select Texta and click Ok.
- In the text box, type “Number=” and click on the Insert Reference icon.
- In the Workflow Variables list, select Number1 and click Ok.
- Click Save.
Add a Build String workflow action
To test starting a workflow with these variables, automatically set when the workflow starts either of the web service methods listed in this tutorial can be used.In this example, the StartWorkflowOnListItem method will be used.
To begin, a dynamic string action must be built to create the associationData XML required in the Call Web Service action. We will use this action to create an association data variable, adata.
- Drag a Build String workflow action onto the design canvas.
- In the Build String textbox, enter the following association data. Refer to the text below for format.
The format for the association data parameter is as follows:
<Data>
<StartDataItem1>value1</StartDataItem1>
<StartDataItem2>value2</StartDataItem2>
<StartDataItem3>value3</StartDataItem3>
</Data>
The workflow we are attempting to start has two Start Data items texta and Number1. Therefore, the association data will be as follows:
<Data>
<texta>testvalue1</texta>
<Number1>12345</Number1>
</Data>
This will set the variable ‘texta’ to testvalue1 and ‘number1’ to 12345. Create the association data variable.
- Click Variables in the Ribbon and select New.
- In the Name, type “adata” and select Single line of text. Click Save.
- In the Store result in field, select adata.
- Click Save.
The two start data variables, texta and number1 have now been combined into the one association data variable.
Using the association data in the Call Web Service action
The association data can now be added to the Call Web Service action.
- In the associationData (string) field, select the Insert Reference icon. In the Workflow Variables section, select adata.
- Check the Encode inserted tokens box and click Save.
Run a Workflow on all existing items in a List/Library
There may be a case where a common process workflow will need to be run on all existing items in a list/library, not only a single item. To achieve this, we must first query all the items within a list and then loop through this result. Within the loop, the current item will be passed to the StartWorkflowOnListItemID web service method. Use the ‘StartWorkflowOnListItemID’ method to start a workflow on each item within a list or library. This will in turn start the workflow on that item.
This type of workflow can be executed once on any item within the list and will then trigger the specified workflow to run on all list items.
Creating a Workflow
Two variables are required for the example.
ItemIDcollection
A collection variable used to store the item ID collection from the initial query.
CurrentItemID
This is used within the For Each action to store the current ID being referenced within the loop, the value will also be passed to the Call Web Service action.
- Click Workflow Settings in the Ribbon and select Variables. Click on New.
- In the Name type “ItemIDcollection” and select Collection as the type. Click Save.
- Select New and in the Name field, type “currentItemID”. Select List Item ID as the type.
Add a Query List Workflow Action
The first step is to query all the items in the current list/library and store the resulting IDs within a collection variable. We can do this using a Query List action.
The Query List action will be set to return each item ID in the list (regardless of the values they contain) to be used within a For Each loop. The result is stored in a collection variable. This variable allows for more than a single value to be returned.
- In the List field, use the drop-down to select the List to query the items. For this example, we will select testlist1.
- In the Recursive field, check the box.
- In Field, select ID and click Add.
- In the drop-down list, select the ItemIDcollection variable.
Note: In the Filter section, you can select to start the workflow on items which meet a specific criteria; for example, only items with a title field which contains the value ‘red’.
Add a For Each Workflow Action
The For Each action will loop through each of the ID values returned, once a collection variable has been populated. The For Each loop will also contain the call web service action that will be starting the target workflow.
- Select and drag a For Each action onto the design canvas.
- In the Target Collection field, select the ItemIDcollection variable. This is the variable which contains the result of the query.
- In the Store result in field, select the currentItemID.
- Click Save.
Add a Call Web Service Workflow Action
The configuration of the web service action is the same as explained in the previous section “Nintex ‘StartWorkflowOnListItem’ web service method example” except that the ID will be the ‘currentID’ variable, which is based on the result of the ‘for each’ loop.
- Select and drag a Call web service action on to the design canvas within the For Each workflow action.
- In the URL field, click on the Insert Reference and select WebURL.
- After WebURL, type “_vti_bin/NintexWorkflow/Workflow.asmx”.
- Enter the credentials for the URL.
- In the Web method field, select Refresh. Select the StartWorkflowOnListItem method.
- Configure the Web service message.
- In the itemID (int) field, click on the Insert Reference icon and select currentItemID.
- In the listName (string) field, click on the Insert Reference icon and select List Name.
- In the workflowName (string) field, enter the name of the workflow that be starting on each item.
The completed workflow will look like this design.