cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Patron
Post Patron

Preventing duplicate entry creation via Patch?

I have a couple of attendance apps for different reasons that all write to the same table called Daily Activity Attendance. Up until this point my technique of If(Blank(LookUp())) record is true patch existing or create new has worked pretty reliably. I have a new app that I made in last few weeks that has been having duplication issues. I am wondering if anyone can tell me what I am missing?

 

I have a gallery of students. In that gallery is a Icon that for OnSelect says:

If(
    IsBlank(
        LookUp(
            '[dbo].[Today Activity Attendance Unfiltered]',
            DailyAttUID = 'User ID' && AttendanceDate_x0020_String = TodayVar
        )
    ),
    Patch(
        '[dbo].[Daily Activity Attendance]',
        Defaults('[dbo].[Daily Activity Attendance]'),
        {
            DailyAttUID: 'User ID',
            AttendanceDate: Today(),
            AfterBusRoom: 1,
            AfterBusRouteID: LookUp(
                LocalRoutes,
                Bus_x0020_Route = BusFinal,
                BusRouteID
            ),
            AfterStopID: LookUp(
                LocalStops,
                Stop_x0020_Name = StopFinal && Time = "Afternoon",
                StopID
            ),
            SignoutTime: Text(
                Now(),
                "[$-en-US]hh:mm:ss"
            )
        }
    ),
    Patch(
        '[dbo].[Daily Activity Attendance]',
        LookUp(
            '[dbo].[Daily Activity Attendance]',
            DailyAttUID = 'User ID' && AttendanceDate_x0020_String = TodayVar
        ),
        {
            AfterBusRoom: 1,
            AfterBusRouteID: LookUp(
                LocalRoutes,
                Bus_x0020_Route = BusFinal,
                BusRouteID
            ),
            AfterStopID: LookUp(
                LocalStops,
                Stop_x0020_Name = StopFinal && Time = "Afternoon",
                StopID
            ),
            SignoutTime: Text(
                Now(),
                "[$-en-US]hh:mm:ss"
            )
        }
    )
)

The table at the top is a SQL View that is:

SELECT        DailyAttUID, [AttendanceDate String]
FROM            dbo.[Daily Activity Attendance] AS att
WHERE        (AttendanceDate = CAST(DATEADD(hour, - 8, GETDATE()) AS DATE))

It seems like if the user taps the button fast enough it creates multiple records. Within 10 seconds it seems. I am wondering if it is running command in parallel? If so can I stop it or maybe deal with it?

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: Preventing duplicate entry creation via Patch?

Hi @BrianHFASPS ,

 

Did you mean that when IsBlank function returns true, then you select the button multiple times, it will create multiple duplicated new records? If so, this is expected behavior I think. Since every clicking returns ture, then everytime it will runs the first part which is  Patch('[dbo].[Daily Activity Attendance]',Defaults('[dbo].[Daily Activity Attendance]'),.... This will always creates a new record with the data you have filled in the related columns.

 

Or did I misunderstand anything?

 

Regards,

Mona

 

Regards,

Mona 

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Post Patron
Post Patron

Re: Preventing duplicate entry creation via Patch?

The way the code should work (I think) is first time the action is run it creates a new record. Then once that record is created any subsequent attempts will simply modify existing records. I have done this in many of my apps where it does a lookup to see if record exists and either creates or modifies. In this instance however it seems I am getting some kind of race condition where user can click icon fast enough that actions are going in parallel almost. I haven't had this issue before though so I am trying to understand what I did wrong maybe this time.

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (7,283)