cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Hydrarian
Level: Powered On

Fail to patch a record

Hi gentlemens,

I've created an app that is in use in my company in order to register and checkout its daily guests. When a guest enters the company he has to scan it's barcode badge in order to register himself with his data and when he leaves he has to scan again it in order to checkout. Some badges are personal, some others no, but this is not the point. When he does the checkout his CDS record is updated with date and time exit. My problem is that, when a badge is scanned more than two times in a day for the checkout, it doesn't update the last record, but most of the time the previous record. I explain bettere with an example:

 

Guest "A" enters at 9 AM and exit at 10 AM. So in the record "A" I have 9 AM - 10 AM

Guest "B" takes the badge left by Guest "A" and enters at 11. He exit at 12. Now I have record "B": 11 AM - (nothing) and record "A" 9 AM - 12 AM

 

And this appends with all the records who have the same barcode. This is an enormous problem because I can't see when most of guests exit from the building. The function I use for the checkout is this one:

 

 

Patch(checkin_1;LookUp(SortByColumns(checkin_1;"cr392_dataoracheckout";Descending;"cr392_dataoraregistrazione";Descending);And(IsBlank(DataOraCheckout);Barcode=BarcodeScanner4_2.Value));{DataOraCheckout: Now()})

 

 

where checkin_1 is the CDS entity where the records are stored, "cr392_dataoracheckout" is the field in which I store the date and time of the checkout, "cr392_dataoraregistrazione"  is the field in which I store the date and time of the checkin.

 

Is there anyone who could help me, please?

5 REPLIES 5

Re: Fail to patch a record

I think the issue is more with how you structure the data, than with Power Apps. In your example, you need to have a key (one field, or a combination) that distinguishes between the records for guest A and for guest B.

One option would be to use a combination of the badge and the guest identifier, although this would only be reliable if a guest would never use the same badge.

Another option would be use a different identifier (either the built-in Guid for the CDS record, or an autonumber field), though you'd need to lookup this value based on the guest and badge (and maybe dates)

Community Support Team
Community Support Team

Re: Fail to patch a record

Hi @Hydrarian ,

Does the barcode badge could identify one Guest user uniquely in your scenario?

 

I assume that the barcode badge could identify one Guest user uniquely in your scenario, based on the formula you provided, I think there is something wrong with it. Please consider modify your formula as below:

Patch(
      checkin_1;
      LookUp(SortByColumns(checkin_1; "cr392_dataoraregistrazione"; Descending); IsBlank(DataOraCheckout) && Barcode = BarcodeScanner4_2.Value);
      {
        DataOraCheckout: Now()
      }
)

or

Patch(
      checkin_1;
      LookUp(checkin_1; Text(cr392_dataoraregistrazione, "mm/dd/yyyy") = Text(Today(), "mm/dd/yyyy") && IsBlank(DataOraCheckout) && Barcode = BarcodeScanner4_2.Value);
      {
        DataOraCheckout: Now()
      }
)

or

UpdateIf(
      checkin_1;
      Text(cr392_dataoraregistrazione, "mm/dd/yyyy") = Text(Today(), "mm/dd/yyyy") && IsBlank(DataOraCheckout) && Barcode = BarcodeScanner4_2.Value;
      {
        DataOraCheckout: Now()
      }
)

 

In addition, please make sure the result the BarcodeScanner4_2.Value formula returns is proper Guest user rather than previous one. So please reset your Barcode Scanner control after your Patch formula:

Patch(
      checkin_1;
      LookUp(checkin_1; Text(cr392_dataoraregistrazione, "mm/dd/yyyy") = Text(Today(), "mm/dd/yyyy") && IsBlank(DataOraCheckout) && Barcode = BarcodeScanner4_2.Value);
      {
        DataOraCheckout: Now()
      }
);
Reset(BarcodeScanner4_2.Value)   /* <-- Add this formula to reset your BarcodeScanner4_2 */

Also set the Reset(BarcodeScanner4_2.Value) formula after your Checkin formula.

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hydrarian
Level: Powered On

Re: Fail to patch a record

Thanks for your answers.

Sorry, my checkout function is this one and not the one I wrote before (I took the wrong powerapp):

 

Patch(checkin_1; First(Sort(Filter(checkin_1; Barcode=BarcodeScanner4.Value);progressivo;Descending));{DataOraCheckout: Text(Now(); "[$-it-IT]dd/mm/yyyy hh:mm")})

 

where "progressivo" is the index.

I can use only the barcode to do the patching because the badges are not personal (They are withdrawn from a bowl in a casual way) and so the guests can insert his data during the checkin, but in the checkout they only scan the barcode on the badge.

Community Support Team
Community Support Team

Re: Fail to patch a record

Hi @Hydrarian ,

Have you taken a try with above formula I provided?

 

Based on the formula you provided, I could not find any syntax error with it. Please consider modify your formula as below:L

Patch(
       checkin_1; 
       LookUp(SortByColumns(checkin_1; progressivo; Descending); Barcode = BarcodeScanner4.Value && IsBlank(DataOraCheckout)); 
       {
          DataOraCheckout: Text(Now(); "[$-it-IT]dd/mm/yyyy hh:mm")
       }
)

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hydrarian
Level: Powered On

Re: Fail to patch a record

Hi, I tried your suggested hint but the problem persists. It keeps update the old records instead of the new one. Any other ideas?

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,701)