Skip to main content

Notifications

Announcements

No record found.

Power Platform Community / Forums / General / To fetch documents fro...
General
Answered

To fetch documents from sharepoint library

Posted on by

I've created a PVA for SharePoint now I wanted to fetch files and documents from SharePoint library when asked by the bot, I've tried to create a flow but unable to do it. Please help with it.

Categories:
  • Re: To fetch documents from sharepoint library

    Hi @Expiscornovus,

    Thank you so much for your help the bot is fetching the right documents. But in the bot response.

    Title and Link not in an arranged manner in HTML Table how can be arranged in right format,Say In any documents iss searched then it should give as Title Link,Title contains name of the document and the link contain link of the document.

     

    Screenshot 2023-09-08 121425.png

    How Can I arrange it properly?

     

    Regards,

    @Anonymous 

  • Verified answer
    Expiscornovus Profile Picture
    Expiscornovus 1,648 on at
    Re: To fetch documents from sharepoint library

    Hi @Anonymous,

     

    Below is another example. It is based on the samples shared earlier.

     

    The flow setup.

     

    1. The Get File (properties only) action uses the Filter Query to search for the words from the Chatbot in the FileLeafRef property (the file name). It also uses a top 5 count, to only retrieve a maximum of 5 items.

    substringof( '@{triggerBody()['text']}',FileLeafRef)

     

    2. The Select is used to only retrieve specific details of the files, in this case Created on and File Name and Link to Item. Below is what I used in the example for the Map field.

    {
     "Created": @{formatdatetime(item()['Created'], 'dd MMM yyyy')},
     "Link": "[@{item()?['{FilenameWithExtension}']}](@{item()?['{Link}']})"
    }

     

    3. A HTML table is temporary created via a HTML table action

     

    4. The outputs is converted into a Results variable and uses a Markdown table as value, which is created with several replace functions via one expression:

    replace(replace(replace(replace(replace(replace(replace(body('Create_HTML_table'), '<table><thead><tr><th>', '| '), '</th></tr></thead><tbody>', concat(' |',decodeUriComponent('%0A%0D'),'|-----------|:-----------:|',decodeUriComponent('%0A%0D'))), '</th><th>', ' | '), '<tr><td>', '| '), '</td><td>', ' | '), '</td></tr>', concat(' |',decodeUriComponent('%0A%0D'))), '</tbody></table>', '')

     

    Btw, if you don't feel comfortable with this type expression feel free to use the apply to each with append to variable approach instead, I have a blog about thathttps://powerusers.microsoft.com/t5/Power-Virtual-Agents-Community/How-to-use-mark-down-to-format-a-table-for-the-bot-response/ba-p/1190942

     

    keywords_search.png

     

    For completion, this is the setup of the Topic of the bot

     

    findbooks.png

  • Re: To fetch documents from sharepoint library

    Hi @Expiscornovus,

    Thank you for your help, can you help me with the flow creation.

    My problem statement is to fetch files and documents from SharePoint library. Say, there is a document library which has multiple folders, my question is that when a user requested for certain files. PVA gives me 5 links related to that document. Please help me out.

     

    Regards @Anonymous.

  • Expiscornovus Profile Picture
    Expiscornovus 1,648 on at
    Re: To fetch documents from sharepoint library

    Hi @Anonymous,

     

    Seems like some of your documents from the Get Files (properties only) outputs are missing a value in the Title column. You can add an not empty check in the Filter Array action as well.

     

    The whole expression would be:

    @and(not(empty(item()['Title'])), contains(item()['Title'], triggerBody()['text']))

     

     

  • Re: To fetch documents from sharepoint library

    Hi, @MattJimison.

    I am facing an error while running the flow can you help me with that.

     

     

  • MattJimison Profile Picture
    MattJimison 488 on at
    Re: To fetch documents from sharepoint library

    Hi, @Anonymous .

     

    Here's a pattern you can follow. After using "Get files (properties only)" as @Expiscornovus suggested, you can iterate through the links and append to a string variable (I called mine "Links" below) in markdown format so that you can output that variable into PVA and it will automatically output the list of links. This makes the title of the document the text you see but you can modify as needed to fit your needs.

     

    MattJimison_0-1693945165932.png

     


    Find this post helpful? Please mark it as the solution and/or provide kudos so that it will help others in the future.

    Cheers,
    Matt

  • Expiscornovus Profile Picture
    Expiscornovus 1,648 on at
    Re: To fetch documents from sharepoint library

    Hi @Anonymous,

     

    There are several ways of achieving this.

     

    The easiest is probably using the Get files (properties) only action for this in Power Automate.

     

    In that action you can a single library and by specifying a filter and use the input from the user in PVA to query that library. I would suggest to have a look at the video (with that approach) in this thread, created by @renatoromaohttps://powerusers.microsoft.com/t5/Calling-Actions-from-PVA/PVA-in-teams-Find-a-file-in-sharepoint-library/m-p/1549499/highlight/true#M751

     

     

    However, you can also try search driven type of approaches if the content is scattered around different sites and libraries:

    - Search REST API approach: https://powerusers.microsoft.com/t5/Building-PVA-chatbots-in/Search-share-point-for-document/m-p/1549570/highlight/true#M710

    - Graph API approach by @HenryJammeshttps://powerusers.microsoft.com/t5/Calling-Actions-from-PVA/Calling-the-Graph-API-to-do-a-document-search-in-PVA/m-p/2101601#M1072

     

     

     

Helpful resources

Quick Links

Exciting News for Copilot Studio Communi…

Get ready to experience a whole new level of engagement with the Copilot Studio…

Celebrating the May Super User of the…

LaurensM is an exceptional contributor to the Power Platform Community…

Check out the Copilot Studio Cookbook…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
renatoromao Profile Picture

renatoromao 6,459

#2
Pstork1 Profile Picture

Pstork1 1,954

#3
Expiscornovus Profile Picture

Expiscornovus 1,648