Microsoft Flow: update SharePoint Document Set

Why?

After a Document Set has been created (see my previous post: https://knowhere365.space/sharepoint-document-set-creation-through-microsoft-flow/) you may want to update some (custom) properties of the new created document set. Unfortunately there are no out-of-the-box Microsoft Flow actions (yet) to do this.

What?

This post will explain step-by-step how you can update an already existing Document set in a SharePoint Online library by using the Send an HTTP request to SharePoint action of Microsoft Flow. These calls are based on the SharePoint REST endpoints where a lot of documentation on can be found here: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service

How?

Some of the variables below are explained in a previous post: https://knowhere365.space/sharepoint-document-set-creation-through-microsoft-flow/ so please check that one first to understand which variables do what.

1) So you already have a site with a library in which you have added your Document set content type and there are some Document sets created in this library. In my example I want to update the Document Set immediately after creation (you cannot create a document set and update properties of it within the same HTTP call) so I added the variable: varCreatedDocumentSetID and set this variable with the unique ID of the newly created set:

The code for the variable:

@{body('Send_an_HTTP_request_to_SharePoint_-_CreateDocumentSet')?['d']?['Id']}

But when you do not create the Document Set in the same Flow just get the unique ID like you would for any other item you needed the ID of (like Get item, Get items, Get file metadata, Get file properties, Triggerbody etc).

2) For simple columns you then just have to add a Send an HTTP request to SharePoint action:

The code for this call:

_api/web/lists(guid'@{variables('varListGUID')}')/items(@{variables('varCreatedDocumentSetID')})

The code for the Headers:

{
  "Content-Type": @{variables('varAcceptHeaderString')},
  "Accept": @{variables('varAcceptHeaderString')},
  "X-HTTP-METHOD": "MERGE",
  "If-Match": "*"
}

TIP: the little icon to the right of the Headers section will toggle between the default Key Value Mode and the Text Mode. In the Text Mode you can copy paste the code so you do not have to add every row separately 💡.

One thing that may need some extra attention is the type SP.Data part of the body. We can get this from the same HTTP request from which we got the List GUID and put in a variable varListItemEntityTypeFullName :

@{body('Send_an_HTTP_request_to_SharePoint_-_ListGUID')['d']['ListItemEntityTypeFullName']}

The code for the Body using the variable varListItemEntityTypeFullName:

{
        "__metadata":{
        "type":"@{variables('varListItemEntityTypeFullName')}" 
     },
	"DocumentSetDescription":"Set created by : @{triggerBody()?['Author']?['DisplayName']}"
}

Also make sure to use the internal / database name of the column that you want to update: see my post https://knowhere365.space/sharepoint-column-internal-name/.

The more complex columns like Choice column, Lookup columns and Managed Metadata are in a league of their own. I will post on those separately ⏱.

20 thoughts on “Microsoft Flow: update SharePoint Document Set

  1. Hi Oliver,
    Regarding a Lookup Column through HTTP Requests (SharePoint REST API), a good explanation can be found at the Microsoft Community Forum: https://powerusers.microsoft.com/t5/Building-Flows/Need-correct-syntax-to-update-lookup-column-property-using-HTTP/td-p/529092

    Regarding the Permissions, a nice post can be found here: https://powerusers.microsoft.com/t5/Webinars-and-Video-Gallery/SharePoint-Permissions-with-Power-Automate-Flow-Using-HTTP/td-p/589419

    Let me know if these are clear –> I am thinking about blogging on these topics myself 👍

    1. Thanks for the links! The first one was quite helpful and I did manage to update the lookup column like this.

      Regarding the permissions I’m still working on it. The link/video explained the same procedure I already used in the past.
      What doesn’t work with my document sets is getting the ID.

      What I want to do is the following:
      1. Loop over all document sets in specific folder (I try to do that with “List folder”). Within the loop I want to do:
      2.1 Get value of lookup column for specific document set (This doesn’t work because I don’t find a function within Sharepoint to give me this data. Do I have to solve this with http as well?)
      2.2 Change permissions (same as in the video). This doesn’t work because I don’t get the right ID of the document set. Within the “List folder”-output I only get a name and some path-like ID.

      Did you already do this and maybe have some hints?

      Best regards,
      Oliver

  2. Hi Django,
    thanks a lot for your pretty helpful guide. It helped me so much!

    What I want to do next is:
    1. Update a lookup column from the document set directly after creating it
    2. In another flow I want to get the document set (based on that lookup column) and change its permissions. I once updated permissions for a normal item via Power Automate so I thought this would be possible as well.

    Any hints on how to do that?

    And if this post gets to you twice, sorry for the duplicate. I wasn’t sure if the post went through correctly yesterday.

    Best regards,
    Oliver

  3. Hi Django,

    Is it possible to change the name on a document set? I can get the title and various other text fields to change, but not the name.

    Any insight would be appreciated.

    Sean

  4. Sure. This hyperlink column contains a link to another library for the same product code, so I want a quick link to enable users to click between Doc sets for the same product within different libraries. Doc sets for the same product have the same Doc Set Name based on Product Code and Product Name.

    1. Site library name is: “Test%20Doc%20Set%20Library”
    2. Doc Set Hyperlink column name: “HWSP Link to CofA Doc Set”. (Replace spaces with “_x0020_”)
    3. “Description” is the display text I want for the hyperlink which is based on a variable called “DocSetName” and text “CoA DS”
    4. ID was obtained from the previous [Update File properties] action which updates the Doc Set properties.

    [Send an HTTP request to Sharepoint] Action:

    Site address: “https://[your site url”]
    Method: PATCH
    Uri: /_api/web/lists/getByTitle(‘Test%20Doc%20Set%20Library’)/items(@{body(‘Update_file_properties’)?[‘ID’]})

    Headers: {
    “Content-Type”: “application/json; odata=verbose”,
    “Accept”: “application/json; odata=verbose”,
    “X-HTTP-TYPE”: “MERGE”,
    “IF-MATCH”: “*”
    }

    Body:
    {
    ‘__metadata’ : { ‘type’: ‘SP.Data.Test_x0020_Doc_x0020_Set_x0020_LibraryItem’ },
    ‘HWSP_x0020_Link_x0020_to_x0020_CofA_x0020_Doc_x0020_Set’ :
    {
    ‘__metadata’: { ‘type’: ‘SP.FieldUrlValue’ },
    ‘Description’: ‘@{variables(‘DocSetName’)} CoA DS’ ,
    ‘Url’: ‘https://[“your site url”]/@{variables(‘DocSetName’)}’
    }
    }

    Hope this helps

    1. Great explanation!
      Very useful for future visitors. Another note in the URL column is that it can have some limitations. As an alternative I often use a single line of text column for storing the hyperlink as text and then use the SharePoint Column Formatting to make it a clickable text or even one of the user friendly Fabric UI icons.

  5. Hi Django,

    Thank you for posting a wonderfully clear guide on how to both create and update document sets using Power Automate. Between your blog and a couple of others I have spent the last couple of days making this work. I’m very happy that my first ever Power Automate workflow is 99% function, as I needed to replace the Sharepoint Designer 2010 Workflow which is being deprecated as of 1-Nov-20. [thanks Microsoft.:-( ]

    However the very last part of the workflow is to update the display text of the hyperlink columns within the newly created doc sets.
    I’m using a “Send an HTTP request to Sharepoint” / Method: POST action, but keep getting the error “Invalid JSON. A token was not recognized in the JSON content.”
    This error appears to relate to the
    Uri:
    /_api/web/lists/getByTitle(‘Product%20Information’)/items(@{body(‘Parse_JSON’)?[‘d’]?[‘Id’]})
    I am assuming this error is because the [‘Id’] from the original [Create DocSet – Parse JSON action] is not being recognised. Though that same [‘Id’] is being recognised and working well for the previous [Update file properties action] which updates all the other Document set metadata in the same newly created doc set.

    But one reply that I saw on another post [https://karinebosch.wordpress.com/2018/11/08/microsoft-flow-create-a-document-set/] was that this function doesn’t work if the library crosses the 5000 list view threshold, which unfortunately my library crossed many years ago, when in it’s pre-cloud ShPt On Prem version.
    Just wondering whether you have had any success updating hyperlink display text in document sets?

    Appreciate any thoughts / feedback you could provide.

    Thanks
    Debbie

    1. Hi Debbie,
      Thank you for checking my blog!
      To make sure that the issue is with the post action of the flow and not with the number items in the library, you could recreate the flow on an empty library?
      It’s a bit of a hassle but that would eliminate issues related to the high number of items in the library.

      From my experience a hyperlink is a special kind of column (like a managed metadata column it has multiple properties) so maybe the post action to update the hyperlink column probably requires a specific JSON syntax?

      1. Thanks Django –
        Great idea to test the list view error theory using a different library.
        So I did have a test library set up, & have just tested it and unfortunately still get the same error, even though the test library has well under the 5000 items.
        So you are probably correct that I need specific JSON Syntax to populate the display text of the hyperlink column within the Doc Set.
        I will keep looking to try to find this…..
        happy for any suggestions on where to look ..;-)

      2. Yippee – I got this to work, and now realise that the Uri code was actually correct. I just added a few spaces in my body text and put the brackets on separate lines and now all working well. I obviously need to learn a bit more on correct syntax formatting. Thanks for your help and hope you have a great week.

  6. Hi Django…

    thank you for this as when moving all our forms to powerapps i was worried about Document sets
    i get to the last step of the flow with no errors then the flow just hangs and does not continue could you assist under major deadlines to get this finished

  7. Hi Django,

    I figured it out. In Dynamic values, when we look for choice column say “ChoiceField1”, there is one more field just below that “ChoiceField1” which is “ChoiceField1 value”. We need to select “ChoiceField1 value” and put it within ” ” in JSON.
    Choice field usually contains three parameters- @odata.type, Id, Value. We need to get the ‘Value’ parameter. In order to get it, we’ll use the dynamic value “ChoiceField1 value” to get that parameter value.

    Thanks,
    Kunal

  8. Hi Django,

    I followed the above steps to update 1 field for the document set – “Additional Comments?” whose internal name is ‘Legal%5Fx0020%5FAction%5Fx0020%5FComments’. Here is the below JSON body written.

    {
    “__metadata”:{
    “type”:”SP.Data.NDALibraryItem”,

    },
    “Legal%5Fx0020%5FAction%5Fx0020%5FComments”:”Testing Com”
    }

    But I got following Invalid JSON error at this step.

    Invalid JSON. An unexpected comma was found in scope ‘Object’. A comma is only valid between properties of an object or between elements of an array.
    clientRequestId: 2d647f1c-87dd-47fe-b312-4281c874d811
    serviceRequestId: aaec5c9f-b027-a000-555c-086bf28ca619

    Can you please assist?

    1. Hi Django,

      I’ve fixed this error. But now I am in need to update ‘Choice’ column. Can you please help me on that?

      Thanks,
      Kunal

Leave a comment