In this post I’m going to show you how to create a list item inside a folder in a SharePoint Designer 2013 workflow even though the “Create List Item” built-in action and even the new rest api do not allow us to do that.
We have a folder inside a custom list and we need to automatically create items inside it using a SharePoint Designer 2013 workflow.
In a SharePoint 2010 workflow we used to simply set the “Folder” property in the built-in action “Create List Item”… and it worked! Our item was correctly created inside the specified folder. Unfortunately in a SharePoint 2013 workflow setting the “Folder” property has no effect. Even the new SharePoint 2013 rest api does not come to our rescue.
We can use the old listdata.svc service to achieve our goal making a rest call to it inside our SharePoint Designer 2013 workflow.
1. Create the headers dictionary
We must build a dictionary to store some headers, specifically the following ones:
Accept: application/json;odata=verbose Content-Type: application/json;odata=verbose
2. Create the data dictionary
Next, we need a dictionary that will contain our request data.
The dictionary must have an entry for each item mandatory fields and an entry to set the item path.
Title: Item 1 Path: <list url>/Folder 1
The item path must be constructed dynamically to point to the folder we want to place our item in.
3. Call the SharePoint REST service
Finally, we are ready to call the SharePoint REST service to create our item inside the list folder.
To do this we need to insert the “Call HTTP Web Service” action in our workflow.
The action url must be constructed dynamically like this:
The http method must be set to POST.
The request headers must be set to the headers dictionary.
The request content must be set to the data dictionary.
This is how the complete workflow should look like:
Now we can publish and run it and see that a new item is correctly created inside our folder.