cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jzcase
Resolver II
Resolver II

Phantom timer trigger causing unwanted timer runs

Guys, I have a real mystery here.

I have a complex canvas app and lots of timers that I use as functions.

In this app I have a form that adds a student to Dataverse (populating 3 different tables with data). The Submit button triggers a sequence of two Timers, addStudent1 and addStudent2

 

Each timer uses a boolean context variable to start it: startAddStudent1 and startAddStudent2, respectively.

 

Generally everything works fine. But there's one weird circumstance where addStudent2 is triggering on its own, causing a bad record to get added to the database.

I've narrowed down the circumstances that cause the phantom trigger--there are 3 fields in the form that check Dataverse for duplicates and notify the user (they all have the same code in their OnChange). But this code never references startAddStudent2.

 

The first time the form detects an existing student in the table, the user can add service, and everything is fine. The second (and subsequent) time the user tries the same thing with a different existing student, addStudent2 triggers immediately.

 

I looked at my variables and startAddStudent2 doesn't appear anywhere unexpected in my app. The duplicate-checking fields don't touch it.

What's more, I made a little debug label to show what happens to my variables when the bug happens:

jzcase_0-1618599970837.png

 

What I discovered is that, when the bug happens, startAddStudent2 never gets set to True. Which means that addStudent2 is triggering independently of its Start condition.

 

Yikes!

 

  • Is it possible for Timers to ever start for reasons other than their Start condition, or the user clicking on them?
  • Are there other debugging tricks I could try to nail down exactly what is happening when my timer triggers?
1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@jzcase 

I would seriously reconsider the concept of using a timer as a function!  If you want a similar and more reliable substitute, you can consider using toggle controls instead.  Put your "function" in the OnCheck of the toggle and set the Default to the variable you are setting.  When the default condition is met the toggle will check and the function will be evaluated.  At the end of the "function" formula, just set your variable back to false, or a condition that will cause the toggle to return to false.

 

Now, to your existing issue.  Yes, if a timer is set to autostart then it will start on its own.  If it is set to loop it will start on its own.

You can use the Monitor tool to assess when things are happening in your app.

 

But overall, a timer should be used to time a duration. 

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

4 REPLIES 4
RandyHayes
Super User III
Super User III

@jzcase 

I would seriously reconsider the concept of using a timer as a function!  If you want a similar and more reliable substitute, you can consider using toggle controls instead.  Put your "function" in the OnCheck of the toggle and set the Default to the variable you are setting.  When the default condition is met the toggle will check and the function will be evaluated.  At the end of the "function" formula, just set your variable back to false, or a condition that will cause the toggle to return to false.

 

Now, to your existing issue.  Yes, if a timer is set to autostart then it will start on its own.  If it is set to loop it will start on its own.

You can use the Monitor tool to assess when things are happening in your app.

 

But overall, a timer should be used to time a duration. 

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

Thank you! That is a good best practice and I will modify accordingly. I've got a couple questions.

 

1. I turned on debugging, saved and published my app, launched the Monitor, and launched my app. However the Monitor is blank. I leave the monitor one while I close and reopen the app in another window. Nothing. I tried changing the Source Filter from Default to Detailed, and I get some telemetry and logging stuff but nothing else.

 

2. Just an observation--all of my timers already had their AutoStart and Loop properties set to false.

3. My addStudent2 timer actually has some justification for being a timer. It has a 5 second duration because there are some housekeeping workflows that do things after addStudent1 completes. Should I leave it as a timer or change it into a toggle and use a different timer to delay it?

Just wanted to update to say: Thank you! Replacing all of my timers with toggles did the trick.

RandyHayes
Super User III
Super User III

@jzcase 

Excellent!  Glad that helped.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (68,764)