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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / send email onTimerEnd ...
Power Apps
Unanswered

send email onTimerEnd getting sent twice

(1) ShareShare
ReportReport
Posted on by 47
I have an app to track time clock punches. The buttons are in a gallery built as a table with 4 options: Check in, lunch out, lunch in, check out. Depending on the button pressed the timer does different things. Check in starts a timer for 4.5 hours and an email is sent at the end of the timer. if the lunch out button is pressed a timer for 27 minutes starts and an email is sent on end.
 
 
 
The timer starts for the check in and work well but I get 2 emails on timer end.
 
And the lunch out timer only runs a few seconds and I get 2 emails.
 
 
 
I have tried changing variables for each button clicked, moving where the timer gets triggered, no luck.
 
Here is the timer on end code:
 
UpdateContext({varLunchTimer:false});
UpdateContext({varLnchTmrAmount: Blank()});

If(var_CI = true || var_LO = true,  
Office365Outlook.SendEmailV2     //Email Recipient
    ("me@email.com",   //Email Subject
    "Time to punch",            //Email Body
    "Punched in at: " & varDayStart & "<br>" &
    "Punched out to lunch at: " & varLunchStart & "<br>" &
    "Punched in from lunch at: " & varLunchStop & "<br>" &
     TextInput1.Text),
    
    varCounting = true,
    Office365Outlook.SendEmailV2   //Email Recipient
    ("me@email.com",    //Email Subject
    "Time to punch",             //Email Body
    "Timer started at: " & varStartCounting & "<br>" &
    "Duration set to: " & Text(varLnchTmrHr,"00") & ":" & Text(varLnchTmrMin,"00") & "<br>" &
     TextInput1.Text),
    ""
);
UpdateContext({varCounting: false});
UpdateContext({var_LO: false});
UpdateContext({var_CI: false});
 
 
Here is the button press code: 
  
UpdateContext({lclCorrection:Blank()});
If(ThisItem.display = Self.Text && ThisItem.enabled,
    //UpdateContext({varLunchTimer: false});
    
    If(
    ThisItem.display = "Check In",
    UpdateContext({var_CI: true}) &&
    UpdateContext({var_LO: false}) &&
    UpdateContext({varDayStart: Now()}) &&
    UpdateContext({varLnchTmrAmount: 16200000}),
    
    ThisItem.display = "Lunch Out",
    UpdateContext({var_CI: false}) &&
    UpdateContext({var_LO: true}) &&
    UpdateContext({varLunchStart: Now()}) &&
    UpdateContext({varLnchTmrAmount: 1620000}),

    ThisItem.display = "Lunch In",
    UpdateContext({var_CI: false}) &&
    UpdateContext({var_LO: false}) &&
    UpdateContext({varLunchStop: Now()}));
    
    UpdateContext({varLunchTimer: If(var_CI = true || var_LO = true, true, false)});
    
    UpdateContext({varTimer: false, varCIEdit: false, varLOEdit: false, varLIEdit: false, varCOEdit: false});
    UpdateContext({CImenuState:0,COmenuState:0,LImenuState:0,LOmenuState:0});    
    Patch(TimeTracker_1, Defaults(TimeTracker_1),
        {Title: glbUser,
          ActivityType: ThisItem.display,
          ActivityDateTime: Text(Now(), "yyyymmddhhmm"), 
          ActivityDate: Now(),
          Notes: TextInput1.Text
        }
        ),
    UpdateContext({lclCorrection: LookUp(TimeTracker_1, Title=glbUser && ActivityType=ThisItem.display && ActivityDate=ThisItem.value)})
);
Reset(TextInput1);
 
 
Hope someone can see where I'm going wrong.
 
 
 
Thank you
Categories:
I have the same question (0)
  • markperrah Profile Picture
    47 on at
    With({data:dcToday.Update},
        Table( 
            //enabled if noValue CheckIn
            {display:"Check In", value: data.CheckIn, enabled: 
            IsBlank(data.CheckIn)},
            
            //enabled if Value CheckIn - noValue CheckOut LunchOut
            {display:"Lunch Out", value: data.LunchOut, enabled: 
            !IsBlank(data.CheckIn) && 
            IsBlank(data.CheckOut) &&            
            IsBlank(data.LunchOut)},
            
            //enabled if value CheckIn LunchOut - noValue LunchIn CheckOut
            {display:"Lunch In", value: data.LunchIn, enabled: 
            !IsBlank(data.CheckIn) && 
            !IsBlank(data.LunchOut) &&             
            IsBlank(data.LunchIn) && 
            IsBlank(data.CheckOut)},
    
            //enabled if value CheckIn - noValue CheckOut
            {display:"Check Out", value: data.CheckOut, enabled: 
            !IsBlank(data.CheckIn) && 
            IsBlank(data.CheckOut)}
        )
    )
    This is the code for how the buttons are setup.
    I have them enabled depending on which buttons have been pressed.
    on start of day only Check In is enabled.
    after Checked In, Lunch out and Check Out are enabled.
    after Lunch In only Check Out is Enabled.
    initially the button says the display name, once clicked it shows the time stamp of that punch and a label above gets visible.
  • Verified answer
    markperrah Profile Picture
    47 on at
    I found a solution.
    Was checking if the label display matched the label display: this is always true.
    Changed to checking if the button text of thisItem is each of the states, is now true only for that state.
     
    UpdateContext({lclCorrection:Blank()});
    If(ThisItem.display = Self.Text && ThisItem.enabled,
        //UpdateContext({varLunchTimer: false});
        
        If(
        btnPunch.Text = "Check In",
        UpdateContext({var_CI: true}) &&
        UpdateContext({var_LO: false}) &&
        UpdateContext({varDayStart: Now()}) &&
        UpdateContext({varLnchTmrAmount: 16200000}),
        
        btnPunch.Text = "Lunch Out",
        UpdateContext({var_CI: false}) &&
        UpdateContext({var_LO: true}) &&
        UpdateContext({varLunchStart: Now()}) &&
        UpdateContext({varLnchTmrAmount: 1620000}),
    
        btnPunch.Text = "Lunch In",
        UpdateContext({var_CI: false}) &&
        UpdateContext({var_LO: false}) &&
        UpdateContext({varLunchStop: Now()}));
        
        UpdateContext({varLunchTimer: If(var_CI = true || var_LO = true, true, false)});
        
        UpdateContext({varTimer: false, varCIEdit: false, varLOEdit: false, varLIEdit: false, varCOEdit: false});
        UpdateContext({CImenuState:0,COmenuState:0,LImenuState:0,LOmenuState:0});    
        Patch(TimeTracker_1, Defaults(TimeTracker_1),
            {Title: glbUser,
              ActivityType: ThisItem.display,
              ActivityDateTime: Text(Now(), "yyyymmddhhmm"), 
              ActivityDate: Now(),
              Notes: TextInput1.Text
            }
            ),
        UpdateContext({lclCorrection: LookUp(TimeTracker_1, Title=glbUser && ActivityType=ThisItem.display && ActivityDate=ThisItem.value)})
    );
    Reset(TextInput1);
     
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,351 Super User 2025 Season 2 on at
    Hi 
     
    can you explain what you have this
    varCounting = true,
    ??
     
    Is that supposed to be an inner if (without the if)??
     
    If in the false, side of your initial check var_C =true etc,  you are adding varCounting
     
    So what I see happening is both of your checks are true
     
    If(var_CI = true || var_LO = true is triggering for sure.
     
    Then in the false side you have varCounting = true, which it probably is, and you aren't setting it to false until the end
     
    So to me it makes sense why its triggering twice.
     
    Where is varCounting Set?
     
    If(var_CI = true || var_LO = true,  
    Office365Outlook.SendEmailV2     //Email Recipient
        ("me@email.com",   //Email Subject
        "Time to punch",            //Email Body
        "Punched in at: " & varDayStart & "<br>" &
        "Punched out to lunch at: " & varLunchStart & "<br>" &
        "Punched in from lunch at: " & varLunchStop & "<br>" &
         TextInput1.Text),
        
        varCounting = true,
        Office365Outlook.SendEmailV2   //Email Recipient
        ("me@email.com",    //Email Subject
        "Time to punch",             //Email Body
        "Timer started at: " & varStartCounting & "<br>" &
        "Duration set to: " & Text(varLnchTmrHr,"00") & ":" & Text(varLnchTmrMin,"00") & "<br>" &
         TextInput1.Text),
        ""
    );

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard