How to Create a List Item Inside a Folder Using a SharePoint Designer 2013 Workflow

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.

Scenario

We have a folder inside a custom list and we need to automatically create items inside it using a SharePoint Designer 2013 workflow.

Item in Folder- Folder

Problem

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.

Solution

We can use the old listdata.svc service to achieve our goal making a rest call to it inside our SharePoint Designer 2013 workflow.

Steps

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

Item in Folder- Headers.png

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

Item in Folder- Data

The item path must be constructed dynamically to point to the folder we want to place our item in.

Item in Folder- Path

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:

https://site/_vti_bin/listdata.svc/SimpleList

Item in Folder- Endpoint.png

The http method must be set to POST.

Item in Folder- Method

The request headers must be set to the headers dictionary.
The request content must be set to the data dictionary.

create_list_folder10

Conclusion

This is how the complete workflow should look like:

Item in Folder - Workflow

Now we can publish and run it and see that a new item is correctly created inside our folder.

Item in Folder- Folder Workflow Completed

Item in Folder- Item Workflow Completed

References

MSDN

11 thoughts on “How to Create a List Item Inside a Folder Using a SharePoint Designer 2013 Workflow

  1. Devin February 28, 2017 / 9:25 pm

    Hi Maria,

    I was hoping that you could help me. I have tried following your instructions above but get a response of BadRequest.

    I have done the ‘Drug Data’ dictionary set up like this (Name | Type | Value):
    Title | String | Lidocaine
    Doses | String | [%Current Item:Doses%]
    Path | String | see variants for here below

    I’ve tried:
    [%Workflow Context: Current Site URL%]/Lists/WebAddName/Folder Name/
    [%Workflow Context: Current Site URL%]/Lists/WebAddName/Folder Name
    [%Workflow Context: Current Site URL%]Lists/WebAddName/Folder Name/
    [%Workflow Context: Current Site URL%]Lists/WebAddName/Folder Name
    /sites/siteCollection/Lists/WebAddName/Folder Name/
    /sites/siteCollection/Lists/WebAddName/Folder Name
    https://mysiteurl/sites/siteCollection/Lists/WebAddName/Folder Name/
    https://mysiteurl/sites/siteCollection/Lists/WebAddName/Folder Name

    I have also tried variants where ‘Folder Name’ is replaced with the variable that contains the name of the folder for the current execution of the WF.

    The URL for the REST call is:
    [%Workflow Context:Current Site URL%]_vti_bin/listdata.svc/WebAddName

    The response code I’ve been getting is:
    BadRequest

    The URL is https://mysite/sites/siteCollection/_vti_bin/listdata.svc/ListTitle (Works in Browser)

    I found that using WebAddName here fails in browser and that using ListTitle in the other places causes a 404 Not Found error in call.

    Any suggestions would be appreciated.

    Thanks,
    Devin

    Like

    • Maria Grazia Merlo March 2, 2017 / 1:54 pm

      Hi Devin. First of all check that you are using the POST verb to make the rest call. Second, try to do a simple test by creating exaclty the same simple list I’m using in the post with only the Title field. Also in the workflow use the same names for the two dictionaries (headers and body). Follow the exact same steps described in the article and it should work. Then move on implementing your real solution step by step.

      Let me know, bye.
      Maria Grazia.

      Like

      • Devin March 2, 2017 / 4:55 pm

        Hi Maria,

        Thank-you for the response. I managed to get it working in a simple list, within the same site, following your instructions. I then moved on to doing it within one of my lists and after some trial and error I have managed to get it close to working with the following:

        I have a list with a content type attached and of the 8 fields I am trying to populate 3 of them, i.e. the 3 are like this:
        Field1 (Number/Integer in WF)
        Field2 (Single Line of Text/String in WF)
        Field 3 (Choice/String in WF) – Actual column contains a space in the name, so tried populating data dictionary with the name “Field 3”, “Field_0x20_3” and “Field_x0020_3” (as it shows when accessing list via REST), of course without the quotes.

        The other thing is that I build the folder/path URL as follows:
        [%Workflow Context:Current Site URL%]Lists/A/[%Current Item:Field 3%]

        A = the URL portion of the list, not the list friendly name, but as it appears in the URL bar.

        If I just do fields 1 and 2 it works, but when I try to populate field 3 it fails with BadRequest, which makes me believe it’s generating the URLs properly but the data dictionary isn’t allowing me to set the choice column. The choice exists because I am setting it to what the user selected for the initial item that triggers it.

        Field 1, Field 2, Field 3
        5, This one triggers other 2, Canada
        5, Province, Canada
        5, City, Canada

        (Not the real context; however, that is the idea, field 2 is different for the subsequent entries but utilises Field 1 & Field 3 to set them the same, failing when field 3, the choice column, is included)

        Thanks for your assistance,
        Devin

        Like

      • Devin March 3, 2017 / 10:04 pm

        Hi Maria,

        I tried converting the choice column to a text field and doing a drop down within an InfoPath form to see if that would then allow me to set Field 3, which has a space in the name.

        In the process I tried something I didn’t think to do before, silly me, and it made it work. The listdata service apparently ignores spaces all together so if I used Field3 as the name in the dictionary it works.

        Thank-you for all your help and I just wanted to let people know encase this also slips there mind with everything else.

        Devin

        Like

      • Maria Grazia Merlo March 10, 2017 / 10:28 pm

        Hi Devin. I’m glad you’ve managed to find a solution. Thank you very much for sharing that information with us.

        Like

  2. Chinh April 16, 2017 / 10:05 am

    Hi Devin, Maria,

    i have problem with choice, lookup fields. it not work with these fields. Please suggest any solution?

    Thanks,
    Chinh.

    Like

    • Devin May 1, 2017 / 1:50 pm

      Hi Chinh,

      Did your read through the thread where I was working through a problem? I know I changed from a choice to a text field; however, did you try the same idea to see if it would also work with a choice field?

      If you use the listdata service run some tests in the browser and make sure you are using the correct field name; which will not include any spaces, i.e. field 1 will be something like field1 and not field_0x20_1.

      Just a thought as this is what it came down to in my case.

      Like

  3. Andy April 27, 2017 / 11:54 am

    Hi Maria,
    I’ looking for a way to place list item in existing folder. I found your description.
    I created on my testing site a new list with the same name, and in SPD I created dictionaries with the same names and nothing….
    After created new item on a list it still appears in main directory.
    I don’t know what is wrong. Is my site or list needs any additional settings?
    Any help would be appreciated.

    Andy

    Like

  4. Rocky April 17, 2019 / 3:54 am

    hello Maria
    is there any way that enables attachment to be included?

    Like

    • Maria Grazia Merlo May 28, 2019 / 5:42 pm

      Dear Rocky, thank you for your question. I will investigate the topic and maybe create a new post on that if feasible.

      Maria Grazia.

      Like

Leave a comment