cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BrianHFASPS
Level 8

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
Community Support Team
Community Support Team

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.
BrianHFASPS
Level 8

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
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 191 members 4,285 guests
Please welcome our newest community members: