cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sudosaurus
Super User
Super User

Loading spinner timer for 30 seconds to queue Collection data before running flow

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:

sudosaurus_0-1699474115474.png

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

 



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus
7 REPLIES 7
M_Ali_SZ365
Impactful Individual
Impactful Individual

Hi @sudosaurus ,

Insert a Timer: Drag a timer control onto your canvas but keep it hidden by setting its Visible property to false.

Set the Duration: Change the timer's Duration property to 30000 for a 30-second countdown.

Stop AutoStart: Make sure the timer doesn’t start automatically by setting AutoStart to false.

Update the Button's OnSelect: In your button's OnSelect code, add a command to start the timer after setting your variables and collections. It'll look something like this:

// Your variable and collection setup code...
Start(Timer1); // This starts the timer
Set(IsLoading, true); // This shows your loading spinner

Trigger the Flow After the Timer: In your timer's OnTimerEnd property, add the code to trigger your flow and to hide the loading spinner:

'BSC-PowerApps-v2'.Run(...); // Add your flow run command here
Set(IsLoading, false); // This will hide the spinner

Handle the Spinner: Your spinner's visibility should be tied to the IsLoading variable. When IsLoading is true, the spinner shows, and when false, it disappears.

With this setup, when you press the button to create a PDF, it starts the timer. The loading spinner appears and stays on screen while the timer counts down. Once the 30 seconds are up, the timer triggers the flow to create the PDF and the spinner goes away. This way, your data has time to load and get included in the PDF.

Please accept this solution if it resolves the issue.
Best regards,
Muhammad Ali

 

sudosaurus
Super User
Super User

@M_Ali_SZ365 

I am seeing this error:

sudosaurus_0-1699478431282.png


Otherwise, everything looks great!

 



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus

Hi @sudosaurus 
Try this

Instead of using Start(Timer1);, directly set the Timer_Start property to true within the button's OnSelect property like this:

// Your variable and collection setup code...
Set(Timer_Start, true); // This should start the Timer1
Set(IsLoading, true); // This shows your loading spinner

 Please accept this solution if it resolves the issue.
Best regards,
Muhammad Ali

sudosaurus
Super User
Super User

@M_Ali_SZ365 

How does it know what Timer_Start refers to? Considering my timer is named PDFPrepTimer.



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus

Hi @sudosaurus 

Try This 

 Set a variable named Timer_Start to true like this: Set(Timer_Start, true);. This variable will control your timer.

Set another variable named IsLoading to true like this: Set(IsLoading, true);. This variable is likely used to show a loading spinner or some other loading indicator.

To make this work, make sure your timer control's Start property is set to Timer_Start. This way, when Timer_Start becomes true, your timer (PDFPrepTimer) will start running.

Please accept this solution if it resolves the issue.
Best regards,
Muhammad Ali

sudosaurus
Super User
Super User

@M_Ali_SZ365 

I have updated as advised in your last post, however I do not see the spinner appearing on screen.

Here's the Fx of the '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);

// 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)})));

Set(Timer_Start, true); // This should start PDFPrepTimer
Set(IsLoading, true); // This shows your loading spinner


For reference I have a testing button to make the spinner modal appear that has its OnSelect set to:

UpdateContext({IsLoading: true})

Which makes this appear:

sudosaurus_0-1699480059906.png

The '30' in the middle is the Timer and it's OnTimerStart property is set to:

Timer_Start


I've set the text property of the timer to the following so that it counts down from 30 to 0:

Text(Time(0, 0, (PDFPrepTimer.Duration-PDFPrepTimer.Value)/1000), "ss")

 

The OnTimerEnd property is set to:

// 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);
Set(IsLoading, false); // This will hide the spinner  

 

Any ideas what I can do to resolve this?



If I helped you solve your problem - please mark my post as a solution and consider giving me a like if you liked my response!

If you're feeling generous you can Buy me a coffee: https://www.buymeacoffee.com/sudosaurus

Hi @sudosaurus 

You'll need to ensure a few things for the loading spinner to function as expected:

The IsLoading variable should be used to control the visibility of the spinner. This means that the spinner's Visible property should be set to IsLoading.
The timer's Start property should be bound to a variable that gets set to true when you want the timer to start (in this case, Timer_Start).
There should be a sufficient delay between setting IsLoading to true and setting it to false. The timer's OnTimerEnd property should contain the logic that sets IsLoading to false, ensuring that the spinner shows for the entire duration of the timer.

Here's what you can do to ensure the spinner works correctly:

Bind the spinner's Visible property to IsLoading.
Use a variable to start the timer and make sure the timer's Start property is bound to this variable.
Only set IsLoading to false in the OnTimerEnd property of the timer after your PDF creation process has been initiated.
Your code in the OnSelect of the 'Create PDF' button should look something like this:

// Set your variables first
Set(varItem, ThisItem);
// ... [other variable sets] ...

// Show the loading spinner
Set(IsLoading, true);

// Data collection and ClearCollect statements go here
// ... [your ClearCollect and ForAll statements] ...

// Start the timer
Set(Timer_Start, true);

Make sure PDFPrepTimer's Start property is set to Timer_Start, and its OnTimerEnd property should contain:

// Trigger the flow when data is ready and stop the spinner
'BSC-PowerApps-v2'.Run(...); // your flow run command
Set(IsLoading, false); // Hide the spinner
Set(Timer_Start, false); // Stop the timer

Remember, the loading spinner control's Visible property must be tied to the IsLoading variable. Make sure this property is set correctly:

Visible = IsLoading

By following these steps, you should be able to see the spinner on the screen for the full duration of the timer (30 seconds) until the data loading and processing are complete.

Please accept this solution if it resolves the issue.
Best regards,
Muhammad Ali

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Top Solution Authors
Top Kudoed Authors
Users online (5,741)