- Create an announcements list and let’s say we want to create a workflow that returns the first one by using the REST api.
- Add a few announcement
- Start SharePoint Designer 2013 and add a list workflow on this announcement list; make sure the workflow is a SharePoint 2013 workflow
- Test your REST call in the browser, for instance mine is the following :
You should get something like this:
You will notice that the response is encoded in xml format; since the $json option is not supported in the SharePoint 2013 REST api, to get the the response in a JSON format you will have to update the Accept and Content-Type http headers of your Rest http call; more specifically :
Accept : application/json;odata=verbose
Content-Type : application/json;odata=verbose
Even if my favorite browser is IE10, I will user Google Chrome to achieve it; start Chrome and install the following Chrome add-in :
When the add-in is installed, you should be able to find the following icon that will allow you to set up your headers
After typing your request request in Chrome you should get the info encoded in JSON
To have a better understanding of structure of the Json response , I usually paste the results in the following JSon parser available online : http://Json.parser.online.fr
d/results(0)/Title should be the path of the first announcement title.
Now, let’s get back to our workflow in SharePoint Designer 2013 :
we need to create the Request header, and this is possible by using a Dictionnary :
- In the existing Stage type Build…
- rename the variable dictionnary as JSonRequestHeader :
- Click on this and click on Build your dictionnary ; add the Accept and the Content-Type headers :
- Now let’s focus on the Http request by adding a Call action
- Click on this and paste your http request
- To associate the JSonRequestHeader variable, select the Call action property:
- set the RequestHeaders property to JSonRequestHeader:
Click ok.
- In the Call action, click on response and associate the response to a new variable : JSonResult (of type Dictionnary).
- After the Call action add a new Get action.
- Add a log activity and display the myTitle variable in the log :
- The final Stage should look like this :
Publish and run the workflow; in the workflow history, you should find your first title :
No comments:
Post a Comment