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)