web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Wait until flow is fin...
Power Apps
Answered

Wait until flow is finished and datasource is refreshed for sure

(0) ShareShare
ReportReport
Posted on by 13

Hi All,

 

I am building a register where I can connect documents from the document library to an entry in a database.

 

Database: Register.

Datafield: ConnectedDocuments (which is a dropdown, consists of choices of documents in document library).

 

I have a form in edit mode where I can add a new document to the register entry. You press a button, this checks is the document already is in the Document Library. If so, it will add the selected document to the ConnectedDocuments using DefaultSelectedItems property.

 

The problem: 

If I have a completely new document which is not in the document library I first have to upload this to the document library. I use a flow for this which works great. Then I should get a new ID for the recently added document. I do not know how to get this out of the flow so I used a different way in the code of the upload button. I look for Filter(Choices([@register].ConnectedDocuments);Id = Last(Documents).ID). To make sure I really get the last document ID i use refresh(Documents) twice allready so I am absolutely sure I should get the last added documents.

 

The problem is that 1 time this works and it adds the last document ID. But most of the time it does not work. It looks like refresh(Documents) takes a longer time to get completely through.

 

How can I set a for..loop kind of function so while the app does not find the real last document ID it will just keep trying to refresh until it really works? Or do you have any other suggestion.

 

The full code on my upload button:

 

If(IsBlankOrError(UploadFileButton_2.FileName);Notify("Selecteer eerst een bestand om te uploaden";NotificationType.Error);

UploadFileFromPowerappstoSharepoint.Run(UploadFileButton_2.FileName;UploadFileButton_2.Media;optSoortDocument_2.Selected.Value);;
Refresh(Documents);;
Refresh(Documents);;
Collect(colDocs;Filter(Choices([register].Gekoppelde_x0020_Documenten);Id = Last(Documents).ID));;
UpdateContext({ToonBijlage:false}));;
Reset(UploadFileButton_2)

 

 

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    Hi @MarcoBechthum ,

    Before we get into your logic, may I suggest a different approach?

    If you send a unique identifier either in the metadata (Update File Properties in Flow) or in the file name itself (I use the ID or the "parent" and the time and date in yymmdd_hhmmss format) and then store this in the parent list, it is a simple matter then to do a lookup into the Library using this identifier to get the ID. The metadata approach is also highly useful for "linking" the document with a numeric field in the Library populated the same way and can then be referenced in a gallery to show all documents belonging to the "parent".

    Happy to elaborate further.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Verified answer
    v-bofeng-msft Profile Picture
    on at

    Hi @MarcoBechthum :

    Do you want to get the ID of the file you added by a flow?

    I’m not sure how your flow is set up, I suggest you can try this solution:

    The point is using "Respond to a PowerApp of flow" action.

    1.JPG

    Then you can use this formula to save the ID to the variable 'var'

     

     

    If(IsBlankOrError(UploadFileButton_2.FileName);Notify("Selecteer eerst een bestand om te uploaden";NotificationType.Error);
    set(var;UploadFileFromPowerappstoSharepoint.Run(UploadFileButton_2.FileName;UploadFileButton_2.Media;optSoortDocument_2.Selected.Value).ID);;/*Execute flow and save the return result of flow to var*/
    Collect(colDocs;Filter(Choices([register].Gekoppelde_x0020_Documenten);Id = Value(var)));;
    UpdateContext({ToonBijlage:false}));;
    Reset(UploadFileButton_2)

     

     

    Best Regards,

    Bof

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    @MarcoBechthum ,

    Another approach from @v-bofeng-msft .

    Please tag whoever you want to continue this thread with. 

  • MarcoBechthum Profile Picture
    13 on at

    Hi Warren, that indeed is a much better way. I am still novice in PowerApps and learning every day. This makes much more sense and makes the app run smoother too. 

     

    Also user @v-bofeng-msft added his reply explaining how to do such a thing. Thank you both for your help. It works like a charm now!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard