10 May’19

D365 General, Dynamics 365Create SharePoint Folder using POST request in MS Flows

Introduction:

This blog explains how to create folders in SharePoint when new record is created in D365 CE.

Use Case:

When new account is created in D365 CE create “Contact Documents” and “Documents” folders in SharePoint.

Pre-Requisites:

  1. D365 CE
  2. SharePoint Online
  3. Microsoft Flow

Steps to be followed:

  1. Sign in to the Microsoft flow. https://flow.microsoft.com/en-us/
  2. Go to My flows -> “+New”-> “+Automated-from blank”

3. Select “When a record is created” trigger and click on create.

4. Select “Organization Name” and “Entity Name”.

5. Click on “+New Step” and select “Compose” Action.

6.   a. Add “Account Name” from Dynamics Content in Input.

b.  Add underscore “_”

c. Click on Expression enter below formula:

toUpper(replace(triggerBody()?[‘accountid’],’-‘,”))

d. Compose should look like below:

7. Now we will create “Main folder in SharePoint” for this account.

8. Click on “+New step” and select “Send an HTTP request to SharePoint” Action.

9. Enter below details:

Site Address: Select the site address from the list.

Method: POST

Uri: _api/Web/GetFolderByServerRelativeUrl(‘account/Output of Compose‘)/Folders

Headers:

Content-Typeapplication/json;odata=verbose
Acceptapplication/json;odata=verbose

Body:

{ ‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’:’account/ Output of Compose‘}

10. Now we will create sub folders inside the main folder.

11. Click on “+New step” and select “Send an HTTP request to SharePoint” Action.

12. Enter below details:

Site Address: Select the site address from the list.

Method: POST

Uri: _api/Web/GetFolderByServerRelativeUrl(‘account/Output of Compose/Contact Documents‘)/Folders

Headers:

Content-Typeapplication/json;odata=verbose
Acceptapplication/json;odata=verbose

Body:

{ ‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’:’account/ Output of Compose/Contact Documents}

NOTE: “Contact Documents” is the sub folder which we want to create in main folder.

13.  Repeat “step no 12” to create “Documents” folders.

Uri: _api/Web/GetFolderByServerRelativeUrl(‘account/Output of Compose/ Documents‘)/Folders

Body:

{ ‘__metadata’: { ‘type’: ‘SP.Folder’ }, ‘ServerRelativeUrl’:’account/ Output of Compose/ Documents‘}

NOTE: “Documents” is the sub folder which we want to create in main folder.

Complete Flow:

Testing Flow

  1. Create new account record in D365 CE.
  2. Check Documents in SharePoint. 
Written by

Vaishali Vyas

Software Engineer

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Expenses in PSA for Fixed Bid and T&M contracts

    23 August’ 2019

    Problem Definition: One of my clients decided to use Expense module in PSA and to his surprise he could see the amount v...

    Read more
  • Setup Dockers

    23 August’ 2019

    Docker is an independent container platform that enables organizations to seamlessly build, share and run any applicatio...

    Read more
  • Qualify Lead in D365 CE: Select which entity records should be created

    20 August’ 2019

    Wave 2019 Updates brought some really sought-after features. Another one which I would like to bring up is the Lead Qual...

    Read more
  • Early Opt-in for October 2019 Wave 2 Updates

    20 August’ 2019

    August 2, 2019 was when the Wave 2 Updates were to be out. And here we are! By now, you should have gotten the option to...

    Read more
  • Setting Unified Interface App Icons

    20 August’ 2019

    Default App Icons for typical D365 environment look like these.But here’s what you can do to change these to put...

    Read more
  • We respect your privacy.
  • This field is for validation purposes and should be left unchanged.