Loading...

Find SharePoint Folder with Particular Name Among Multiple Document Libraries Using Cloud Flow (Part 7 of 8)

Find SharePoint Folder with Particular Name Among Multiple Document Libraries Using Cloud Flow (Part 7 of 8)
This is the seventh post in a series of Automating SharePoint Integration with Dataverse using Power Automate. You can check out the other posts via these links (Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, Part 8)

In the Part 3 post, I have explained how to automatically create subfolders under the Document Library. If the requirement is to process/send the documents stored in one of the subfolders automatically created, it is a relatively simple process by retrieving the Document Location of the row and picking up all the files from the subfolder under the whole path

It is harder when the users are creating more Document Locations manually to store the documents based on the specific requirement each row is related to more than one Document Location. Now, the challenge is to find the correct folder out of multiple Document Locations. Thanks to Benedikt Bergmann for the inspiration of this blog post.


These are all the steps included in the cloud flow for this solution. The following sample scheduled flow would be running at a specific time to query the list of Applications with "Pending Approval Notification" status and send the documents from the "Approval Letters" subfolder of the application. This post will focus on how to find the documents from the "Approval Letters" subfolder out of multiple Document Locations related to the Application.


The flow trigger is Recurrence based on the specific schedule.

This is the FetchXML used to query the list of Applications with "Pending Approval Notification" status. In the same FetchXML, related Document Location and its parent Document Locations are retrieved as <link-entity> to get the complete URL of the SharePoint folder.
<fetch>
<entity name="lzw_application">
<attribute name="lzw_applicationid" />
<filter>
<condition attribute="statuscode" operator="eq" value="859130000" />
</filter>
<link-entity name="sharepointdocumentlocation" from="regardingobjectid" to="lzw_applicationid" alias="DL4">
<attribute name="relativeurl" />
<link-entity name="sharepointdocumentlocation" from="sharepointdocumentlocationid" to="parentsiteorlocation" link-type="outer" alias="DL3">
<attribute name="relativeurl" />
<link-entity name="sharepointdocumentlocation" from="sharepointdocumentlocationid" to="parentsiteorlocation" link-type="outer" alias="DL2">
<attribute name="relativeurl" />
<link-entity name="sharepointdocumentlocation" from="sharepointdocumentlocationid" to="parentsiteorlocation" link-type="outer" alias="DL1">
<attribute name="relativeurl" />
<link-entity name="sharepointsite" from="sharepointsiteid" to="parentsiteorlocation" link-type="outer" alias="SPS">
<attribute name="absoluteurl" />
</link-entity>
</link-entity>
</link-entity>
</link-entity>
</link-entity>
</entity>
</fetch>
Similar to the diagram below, the folder structure of the Application is based on the Contact. That is the reason why there are x4 <link-entity> tags for sharepointdocumentlocation. The alias DL4 is for the Document Location directly related to the Application. DL3 is for "lzw_application" subfolder. DL2 is for the Document Location of the Contact. DL1 is the "contact" document library and SPS is to query the SharePoint site URL.


For each Application retrieved from the previous List Rows, list the Document Location folder to see if the folder contains the specific folder (in the next step). List folder action from SharePoint connector requires two parameters. The Site Address can be populated with the absoluteurl value of the SPS alias (SharePoint site) from the result.
@{items('Apply_to_each_Document_Location_of_Application')?['SPS.absoluteurl']}

The File Identifier parameter needs to be populated with the complete folder path and it can be achieved by concatenating the relativeurl of the related Document Location (DL4) and its parent Document Locations (DL1, DL2, DL3). encodeUriComponent function needs to be used to replace some of the characters (Space with %20, / with %2F, etc.) to make the value acceptable by the File Identifier parameter.
encodeUriComponent(concat('/', items('Apply_to_each_Document_Location_of_Application')?['DL1.relativeurl'], '/', items('Apply_to_each_Document_Location_of_Application')?['DL2.relativeurl'], '/', items('Apply_to_each_Document_Location_of_Application')?['DL3.relativeurl'], '/', items('Apply_to_each_Document_Location_of_Application')?['DL4.relativeurl']))

From the output of the List folder action, filter the item where the Name is "Approval Letters". After that, the flow will only process only the Document Locations which has the "Approval Letters" folder by checking the number of items from the output of the filter step.
length(body('Filter_array_for_Approval_Letters_folder'))


The step is quite similar to the one in step 2. The only difference is the '/Approval Letters' at the end of the folder path to query all documents under the "Approval Letters" subfolder. Then, the files can be processed or sent in the subsequent step.
encodeUriComponent(concat('/', items('Apply_to_each_Document_Location_of_Application')?['DL1.relativeurl'], '/', items('Apply_to_each_Document_Location_of_Application')?['DL2.relativeurl'], '/', items('Apply_to_each_Document_Location_of_Application')?['DL3.relativeurl'], '/', items('Apply_to_each_Document_Location_of_Application')?['DL4.relativeurl'], '/Approval Letters'))


Summary

When we automate SharePoint Integration with Dataverse using Power Automate, we need to handle multiple scenarios to cover different situations such as creating Document Locations manually. When handling such scenarios, related Document Location and its parent Document Locations can be retrieved in a single FetchXML query by using link-entity.

Published on:

Learn more
Linn's Power Platform Notebook
Linn's Power Platform Notebook

A blog about Dynamics 365 and Power Platform (canvas apps in Power Apps and flows in Power Automate).

Share post:

Related posts

Power Automate: Fixing the ‘ChildFlowNeverPublished’ Error

While trying to enable one of the cloud flows from a managed solution I had installed, I encountered the following error:  “{“erro...

1 day ago

Power Automate – Information regarding the end of support for Document Automation Toolkit

On November 15, 2025, the Document Automation Toolkitfeature in Power Automate reached of support. How does this affect me? Makers will no lon...

1 day ago

AI Agent Security: Applying Presume Breach and Least Privilege in Microsoft Copilot Studio & Power Automate

AI-backed tools are powerful and easy to develop. Give an agent access and clear instructions, and in many cases, it can just do the job. Howe...

2 days ago

Power Automate – Enable process mining integration in process map

We are announcing the ability to enable process mining integration in process map in Power Automate. This feature will reach general availabil...

4 days ago

How to Automate Image Descriptions with AI Builder in Power Automate

In today’s fast-paced digital world, automating repetitive tasks not only saves time but also significantly improves productivity. Microsoft n...

4 days ago

How to Identify and Update Power Automate HTTP Request Trigger Flows Before November 2025

Few weeks back, while working on one of our Power Automate flows, we noticed a banner warning on the HTTP Request trigger step. Microsoft has ...

10 days ago

Power Automate – HTTP and Teams webhook trigger flows are moving to new URLs

As of August 2025, Power Automate flows and Agent flows (Copilot Studio) with HTTP triggers or Teams Webhook triggers that have logic.azure.co...

11 days ago

How to Automate Document Signing with DocuSign in Power Automate

Introduction In an earlier Inogic post, “Streamlining E-Signatures in Multi-Step Forms with Power Pages and DocuSign Integration”, Our previou...

14 days ago

Power Automate Retry and Error Handling Patterns for Reliable Power Pages Integrations

When Power Pages integrates with Power Automate, reliability becomes key. Portal users expect instant responses — whether submitting a form, u...

16 days ago

Handling Large Files in Power Automate

Power Automate can handle large files, but how large? SharePoint Online supports files up to 250 GB, which sounds generous until you try movin...

16 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy