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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Workaround for OnSucce...
Power Apps
Answered

Workaround for OnSuccess/OnFailure of SubmitForm running parallelly to code that comes after it?

(0) ShareShare
ReportReport
Posted on by 17

I have a block of code where I set a variable to an initial value, followed by a number of SubmitForm() functions in a row. I change the variable's value in the OnSuccess/OnFailure of the forms, and once the SubmitForm() functions are done, I run an If-else block based on the value of the variable. However, it seems that the OnSuccess/OnFailure of the SubmitForm() functions run parallely to the code that comes after it, since the variable remains the initialized value that I set before the SubmitForm() functions. I verified this by running a simple increment counter on success, and triggered a success, to see what executes first (or simultaneously), and it reconfirmed my suspicion.

 

The main code block is:

 

Set(AttachmentFailureLog, Blank());

Set(LoadingOverlay, true);

SubmitForm(Form1);
SubmitForm(Form2_9);
SubmitForm(Form2_10);
SubmitForm(Form2_11);
SubmitForm(Form2_12);
SubmitForm(Form2_13);
SubmitForm(Form2_20);

If(IsBlank(AttachmentFailureLog),

//success code

,

//failure code)

 

___________________________________________________________________________________________________________________________________________

 

The OnFailure of the first form is :

 

Set(isEditable, false);
Set(LoadingOverlay, false);
Notify("There was an error submitting the request, please contact admin", NotificationType.Error);

Set(AttachmentFailureLog,"Request resubmit failed at "&Now())

___________________________________________________________________________________________________________________________________________

 

I forced a failure and got the appropriate notification, but the If-else block executed the code that is supposed to run on AttachmentFailureLog being blank.

 

My question is how do I perform a workaround so that the next part only runs once all the SubmitForms OnSuccess/OnFailure codes have finished running?

Categories:
  • Verified answer
    Matt_uhb Profile Picture
    102 on at

    You could insert a Timer control on the page, and set its Visible parameter to false.

    At the end of the first code block set a variable varStartTimer to true -  Set(varStartTimer, true). 

    On the timer control,  set the Start value to varStartTimer, and the duration to, say, 30000 miliseconds (30 seconds), then set the OnEnd value whatever the second part of your code block was.

    If this is successful, reduce the timer by half and try again.

    Repeat until it fails and increase the timer by 100 miliseconds.

    Repeat again with subsequent increases until it is successful again.

    You've now found the sweet spot between speed and successful performance.

  • VikrantG Profile Picture
    17 on at

    Thanks Matt! I kept it at 5 seconds and it worked. Had to set varStartTimer to "false" at the end of the OnEnd code block as well btw, otherwise it doesn't run again. Your solution has helped me a lot, thank you !!

  • Matt_uhb Profile Picture
    102 on at

    Thanks Vikran, 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard