Using Rest Services in Workflow:
Let's start with SharePoint Designer workflow which accesses the SharePoint List data using REST call i.e Web Service Call
SharePoint List
The following is a list structure which we are referencing for our application.

Figure 1: SharePoint
Step 1: Create Site Workflow
Using SharePoint Designer create site workflow. Make sure you select SharePoint 2013 Workflow as the platform type.

Figure 2: Workflow
Step 2: Create Workflow Stage.
Let’s start by creating a new stage.

Figure 3: Stage
Workflow Stages
Stage 1: Workflow Initialization: The following variables get initialized at this stage:
ServiceURL: Here's the URL.

Figure 4: Initialized
Index: Create Index variable of type Integer & set it to 0.

Figure 5: Index
Service Call Header: Next, we add a Dictionary variable (Build a Dictionary action), call it requestHeaders and initialize it as this:

Figure 6: Header
Both “Accept” and “Content-Type” entries are of the String type and they both contain the value “application/json;odata=verbose”. SharePoint REST API understands this and sets the response content type appropriately as JSON. If we don’t pass these values, the output would come as XML.

Figure 7: Accept
Stage 2: Web Service Call
Add a Call as HTTP Web Service action and set its properties. The request will be the url variable:

Figure 8: Webservice
Set workflow variable "ServiceURL" as Web Service URL.
HTTP method as "GET".

Figure 9: Get
Response content will go to a new variable called responseContent.(type - Dictionary).
Response headers will go to a new variable called responseHeaders.(type - Dictionary).
Response code will go to a new variable called responseCode.(type - Dictionary ).
Then we set the request headers to be the requestHeaders variable we created just now, by clicking on the properties for the Call on HTTP Web Service action:

Figure 10: Call set variable as needed.

Figure 11: Variable
Process Web Service Response
Now, create a new stage, call it " Process Web Service Response".
At the end of the " Web Service Call" add a Go to Process Web Service Response stage.

Figure 12: Loop


List Item Looping

Figure 13: TaskItem

Figure 14: String

Figure 15: item

Figure 16: listitem
Final Workflow

Figure 17: Workflow1

Figure 18: wk2

Figure 19: wk3

Figure 20: wk4
Check Workflow Execution
Add some list item's.

Figure 21: newitem
Follow below steps

Figure 22: follow
Reference:
http://www.c-sharpcorner.com/UploadFile/58e23e/call-http-web-service-using-sharepoint-designer-2013-spd/
Let's start with SharePoint Designer workflow which accesses the SharePoint List data using REST call i.e Web Service Call
SharePoint List
The following is a list structure which we are referencing for our application.
Figure 1: SharePoint
Step 1: Create Site Workflow
Using SharePoint Designer create site workflow. Make sure you select SharePoint 2013 Workflow as the platform type.
Figure 2: Workflow
Step 2: Create Workflow Stage.
Let’s start by creating a new stage.
Figure 3: Stage
Workflow Stages
Stage 1: Workflow Initialization: The following variables get initialized at this stage:
ServiceURL: Here's the URL.
Figure 4: Initialized
Index: Create Index variable of type Integer & set it to 0.
Figure 5: Index
Service Call Header: Next, we add a Dictionary variable (Build a Dictionary action), call it requestHeaders and initialize it as this:
Figure 6: Header
Both “Accept” and “Content-Type” entries are of the String type and they both contain the value “application/json;odata=verbose”. SharePoint REST API understands this and sets the response content type appropriately as JSON. If we don’t pass these values, the output would come as XML.
Figure 7: Accept
Stage 2: Web Service Call
Add a Call as HTTP Web Service action and set its properties. The request will be the url variable:
Figure 8: Webservice
Set workflow variable "ServiceURL" as Web Service URL.
HTTP method as "GET".
Figure 9: Get
Response content will go to a new variable called responseContent.(type - Dictionary).
Response headers will go to a new variable called responseHeaders.(type - Dictionary).
Response code will go to a new variable called responseCode.(type - Dictionary ).
Then we set the request headers to be the requestHeaders variable we created just now, by clicking on the properties for the Call on HTTP Web Service action:
Figure 10: Call set variable as needed.
Figure 11: Variable
Process Web Service Response
Now, create a new stage, call it " Process Web Service Response".
At the end of the " Web Service Call" add a Go to Process Web Service Response stage.
- Add a Get an Item from a Dictionary action, set the item as d/results, the source variable reponseContentand the output to a new variable of type Dictionary called List.
- Then count items from this list variable using a Count Items in Dictionary action and store the result in a new Integer variable called TotalListItem. This variable will tell us how many times we have to loop.
- Finally, create a new Integer variable called index and set it to 0 (Set Workflow Variable), this will be the loop index.
Figure 12: Loop
List Item Looping
- Add a loop (Loop n Times), call it Loop Task Items, and set the loop variable to TotalListItem variable.
- Inside the loop, get value d/results([%Variable: index%]) using a Get an Item from a Dictionary action from responseContent and store it in a new Dictionary variable called CurrentItem.
- Get some fields (Get an Item from a Dictionary) from the CurrentItem variable, such as Title and store them in appropriate variables and do whatever you want with them, like logging its contents (Log).
- Its Time to increment the loop counter: add a Do Calculation action and in it increment the index variable into a new Integer variable called IncrementCounter.
- Then set the index variable to be the IncrementCounter(Set Workflow Variable).
- Finally exit the loop and set the workflow status (Set Workflow Status action) to Finished.
- At the end of the stage, select Go to End of Workflow.
Figure 13: TaskItem
Figure 14: String
Figure 15: item
Figure 16: listitem
Final Workflow
Figure 17: Workflow1
Figure 18: wk2
Figure 19: wk3
Figure 20: wk4
Check Workflow Execution
Add some list item's.
Figure 21: newitem
Follow below steps
Figure 22: follow
- go to site content
- Click Site Workflow
- Select Appropriate workflow
- Click it
- Workflow started.
http://www.c-sharpcorner.com/UploadFile/58e23e/call-http-web-service-using-sharepoint-designer-2013-spd/
No comments:
Post a Comment