Hello,
I have a Power App that has a button that runs a flow to create a PDF button - simples.
The main issue is that the onSelect code is processed so fast that it doesn't have enough time to collect the data from various SP list sources and hence doesn't include this dynamic data in the PDF unless the user waits a few minutes and does it again - then it works OK.
This is the Fx from the OnSelect property of my 'Create PDF' button:
// Set your variables first
Set(varItem, ThisItem);
Set(varBuildingPhoto, LookUp(BuildingPhotos, Title = ThisItem.spBuilding).'Link to item');
Set(varBuildingPhotoID, LookUp(BuildingPhotos, Title = ThisItem.spBuilding).ID);
// Add a loading indicator
Set(IsLoading, true);
// Your data collection and ClearCollect statements go here
// THIS INCLUDES ALL THE TOPIC HEADERS
ClearCollect(colSubtopics1, Distinct(Filter(SubtopicArgEvi_1,Building=varItem.spBuilding),Topic));
// THIS IS THE DISTINCT COLLECTION OF ORDER OF TOPICS
ClearCollect(colSubtopics, ForAll(Sequence(CountRows(colSubtopics1)), Patch(Last(FirstN(colSubtopics1,Value)),{Order:Value})));
ClearCollect(colTempAllSubtopics, AddColumns(Filter(SubtopicArgEvi_1,Building=varItem.spBuilding),"TopicOrder",0,"SubtopicOrder",0));
Clear(colTempAllSubtopicsB);
ForAll(colTempAllSubtopics, Collect(colTempAllSubtopicsB, {
Top: colTempAllSubtopics[@Topic],
SubTop: colTempAllSubtopics[@Subtopic] & " - " & colTempAllSubtopics[@'Subtopic Breakdown'],
Arg: colTempAllSubtopics[@Argument],
Evid: colTempAllSubtopics[@Evidence],
TopOrder: LookUp(colSubtopics,Value=colTempAllSubtopics[@Topic]).Order+2
}));
Clear(colAllSubtopics);
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=3)), 3.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=3), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=4)), 4.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=4), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=5)), 5.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=5), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=6)), 6.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=6), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=7)), 7.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=7), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=8)), 8.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=8), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=9)), 9.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=9), Value)), {SubTopOrder: RoundUp(Value, 2)})));
Collect(colAllSubtopics, ForAll(Sequence(CountRows(Filter(colTempAllSubtopicsB, TopOrder=10)), 10.1, 0.1), Patch(Last(FirstN(Filter(colTempAllSubtopicsB, TopOrder=10), Value)), {SubTopOrder: RoundUp(Value, 2)})));
// After your data is collected, update the loading indicator
Set(IsLoading, false);
// Use the If function to prevent PDF generation until data is loaded
If (!IsLoading,
// Trigger the workflow when data is ready
'BSC-PowerApps-v2'.Run(htmlBody_1.HtmlText, varBuildingPhoto, Now(), varBuildingPhotoID, htmlBody_2.HtmlText, htmlBody_3.HtmlText, varItem.ID),
Notify("Please wait for data to load", NotificationType.Warning)
)
I have this loading spinner in a container that is displayed when IsLoading is set to true:

and consequently this is hidden when IsLoading is set to false.
The problem is that this displays for about a second and seems a bit pointless - and not making any difference to the data being loaded in time.
Having spent a good couple of hours trying to get this working with my pal ChatGPT, it was suggested that I use a timer and set its duration to my chosen number of seconds (I thought 30 would be a good shout). However all the examples I was being given were unsupported in PowerApps.
Essentially I need a timer to start when IsLoading is set to true and have the loading spinner sit there for 30 seconds and then once the timer ends, the OnSelect statement then completes and starts the 'BSC-PowerApps-v2'.Run command to trigger the Power Automate flow.
How I get there is why I'm posting here.
What's the best way of achieving this? Whether its done via my spinner box or whether it has to be via a loading screen, I don't really mind.
Thanks,
Chris