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 / Patch issue Dataverse
Power Apps
Unanswered

Patch issue Dataverse

(0) ShareShare
ReportReport
Posted on by

I have a power app which people use to scan in and scan out of the building, they use a tag or manual input (mostly a tag with NFC) to check in or check out. 

The data is saved in a simple dataverse table with the following columns: 
Scancode / 
StartDate / StartTime / EndDate / EndTime  

 

They scan a code from an NFC tag, which is entered in a text input control in my app. On the OnChange, it checks the following things (see code below):

  1. if it is a valid tag (code)
  2. If they haven't clocked in the past 30 seconds.
  3. Depending on whether they checked in or out the last time, it moves to a different success screen.
    1. If they checked out they move to a checkout screen;
    2. If they checked in they moved to a checking screen. 
  4. In addition, it calculates the hours between start end now()

However, in our testing fase, people are experiencing that they need to scan twice. First time, they move to the succes screen, but it isnt patched to the database. Second time it works.
The issue doesn't happen with everybody and i cannot see a pattern. 

Can somebody help me with this issue?

 

Below my code.

 

 

Set(varScanCode, Trim(Self.Text));
 

UpdateContext({ ScanCode: varScanCode, varSpinner: true });

If(

   IsBlank(LookUp(ExtraEmployees, 'Tag Nummer' = varScanCode)),

   UpdateContext({ varLabel: "Invalid code, please scan again!}),

   Set(varLastPatch, Blank());

   Set(varMedewerkerPersnr, LookUp(ExtraEmployees, 'Tag Nummer' = varScanCode).Persnr);

   With(

       {

           OpenRecord: LookUp(KloksysteemLogs, code = varScanCode && IsBlank(EindTijd)),

           LastUpdate: First(SortByColumns(Filter(KloksysteemLogs, code = varScanCode),"modifiedon",SortOrder.Descending)).'Modified On' 

       },

       If(

           !IsBlank(LastUpdate) && DateDiff(LastUpdate, Now(), TimeUnit.Minutes) < 0.5,

           UpdateContext({varLabel:"You can only clock in or clock out again 30 seconds after your last action."}),

           If(

               !IsBlank(OpenRecord),

               // Clock out

               Set(

                   varLastPatch,

                   Patch(

                       KloksysteemLogs,

                       OpenRecord,

                       {

                           code: varScanCode,

                           EndDate: DateValue(Now()),

                           EndTime: Now(),

                           Uren: Round(DateDiff(OpenRecord.StartTime, Now(), TimeUnit.Minutes)/602)

                       }

                   )

               );

               Navigate(SuccesScreenOutScreenTransition.Fade),

               // Clock in 

               Set(

                   varLastPatch,

                   Patch(

                       KloksysteemLogs,

                       Defaults(KloksysteemLogs),

                       {

                           code: varScanCode,

                           StartDate: DateValue(Now()),

                           StartTime: Now(),

                           EndDate: Blank(),

                           EndTime: Blank()

                       }

                   )

               );

               Navigate(SuccesScreenInScreenTransition.Fade)

           )

       )

   )

)

 

I have the same question (0)
  • Power Platform 1919 Profile Picture
    2,056 on at
    Hi ,

    TextInput.OnChange is unreliable for scan logic because it can fire multiple times and at unpredictable moments.
     
    With NFC or scanner input, the value may arrive in parts, or the event can be retriggered by focus changes, resets, or navigation.
     
    Since Patch() is an async Dataverse call, Navigate() can run even if the write has not completed or has failed, which leads to the “success screen but no record” scenario.
     
    Microsoft documents OnChange as an edit-detection event, not a guaranteed single action trigger, which makes it unsuitable for transactional logic.

    A better pattern is to use the text input only to capture the value (for example via TextInput1.Text or a variable) and move all logic to a button’s OnSelect. A button executes once, is easy to disable while processing, and allows you to store the Patch() result in a variable and validate it before navigating. This makes the flow deterministic.

    When you use Set(varResult, Patch(...)), Power Fx/ power apps runtime waits for the Patch operation to complete and then stores the returned record in the variable

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
Kalathiya Profile Picture

Kalathiya 421

#2
WarrenBelz Profile Picture

WarrenBelz 386 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 339 Super User 2025 Season 2

Last 30 days Overall leaderboard