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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Avoid inserting duplic...
Power Apps
Unanswered

Avoid inserting duplicate records in a form only if the records are entered by the same user; if there are duplicates from different users, leave them.

(1) ShareShare
ReportReport
Posted on by 82

Hi all!


I've created an app linked to a SharePoint list where I want to prevent the user from submitting the same record multiple times. For example, based on the selection of Quarter and Month, if they have already been selected, it should not allow me to enter a new record. Instead, if they have already been chosen, it should replace the existing record without creating a new one.


There's an exception: if there are identical records from the same combination of quarter and month but created from different users, I need to leave them.



With(

    {

        _get_record: LookUp(

            Chargeability_New,

            Month.Value = DataCardValue8_1.Selected.Value && Quarter.Value = DataCardValue8.Selected.Value

        ),

        currentUserID: User().FullName

    },

    If(

        IsBlank(_get_record),

       

        Patch(

            Chargeability_New,

            Defaults(Chargeability_New),

            Frm_Chargeability.Updates

        );

        Notify(

            "Nuovo record creato",

            NotificationType.Success

        )

    );

    If(

        Not(IsBlank(_get_record)),

       

        Patch(

            Chargeability_New,

            _get_record,

            Frm_Chargeability.Updates

        );

        Notify(

            "Record sovrascritto all'esistente",

            NotificationType.Warning

        )

    );

    Navigate('Gallery Screen')

)



I tried this code, but it only works when it overwrites identical records created by the same user. If I enter a record identical to another user's, it still overwrites it; in this case, it should leave them both.


How could I solve this?


Thanks

 

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @Fe3 

     

    can u try this:

     

     

    With(
     {
     currentUserID: User().FullName,
     _get_record: LookUp(
     Chargeability_New,
     Month.Value = DataCardValue8_1.Selected.Value &&
     Quarter.Value = DataCardValue8.Selected.Value &&
     CreatedBy.FullName = currentUserID 
     )
     },
     If(
     IsBlank(_get_record),
     
     Patch(
     Chargeability_New,
     Defaults(Chargeability_New),
     Frm_Chargeability.Updates
     ),
     Notify(
     "New record created",
     NotificationType.Success
     ),
     
     Patch(
     Chargeability_New,
     _get_record,
     Frm_Chargeability.Updates
     ),
     Notify(
     "Record overwritten",
     NotificationType.Warning
     )
     ),
     Navigate('Gallery Screen')
    )
    

     

     

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • madlad Profile Picture
    2,637 Moderator on at

    Hi!

     

    I hope I'm understanding correctly, you want to overwrite identical records, but not if it's different users that submit them?

    If so, I think you can modify _get_record in the With(...) like the following:

    _get_record: LookUp(
     Chargeability_New,
     Month.Value = DataCardValue8_1.Selected.Value && 
     Quarter.Value = DataCardValue8.Selected.Value &&
     CreatedBy.Email = User().Email
    )

    ^This just also adds in a requirement that it was created by the current logged in user.

     

    Hope this helps! 🙂

  • Sam_Fawzi Profile Picture
    898 Super User 2026 Season 1 on at

    Hi @Fe3 ,

     

    You need to include a check for the current user in the LookUp function. This way, you ensure that you are only comparing records created by the same user. Here is how you can modify your code to achieve this:

     

     

    With(
     {
     _get_record: LookUp(
     Chargeability_New,
     Month.Value = DataCardValue8_1.Selected.Value && 
     Quarter.Value = DataCardValue8.Selected.Value && 
     CreatedBy.Value = User().FullName // Ensure you have a column 'CreatedBy' in your list that stores the creator's username
     ),
     currentUserID: User().FullName
     },
     If(
     IsBlank(_get_record),
     Patch(
     Chargeability_New,
     Defaults(Chargeability_New),
     Frm_Chargeability.Updates,
     {
     CreatedBy: currentUserID // Ensure to store the creator's username in a 'CreatedBy' column
     }
     );
     Notify(
     "Nuovo record creato",
     NotificationType.Success
     )
     );
     If(
     Not(IsBlank(_get_record)),
     Patch(
     Chargeability_New,
     _get_record,
     Frm_Chargeability.Updates
     );
     Notify(
     "Record sovrascritto all'esistente",
     NotificationType.Warning
     )
     );
     Navigate('Gallery Screen')
    )

     

     

     

    Hope that will help!

    Cheers,

     

  • FR-27081326-0 Profile Picture
    82 on at

    Thanks @madlad !

    This works in case different users have the same code as it doesn’t overwrite them. But if the same user creates the same code instead of overwriting it creates another.

    How could I add this second condition (same user, same record overwriting?)

  • madlad Profile Picture
    2,637 Moderator on at

    @Fe3 

    The previous statement you provided should work when it's used with my original suggestion; However, since it's still causing an issue, try the following code:

     

    With(
     {
     _get_record: LookUp(
     Chargeability_New,
     Month.Value = DataCardValue8_1.Selected.Value && 
     Quarter.Value = DataCardValue8.Selected.Value &&
     CreatedBy.Email = User().Email
     )
     },
     If(
     IsBlank(_get_record),
     Patch(
     Chargeability_New,
     Defaults(Chargeability_New),
     Frm_Chargeability.Updates
     );
     Notify(
     "New record created",
     NotificationType.Success
     ),
     Patch(
     Chargeability_New,
     _get_record,
     Frm_Chargeability.Updates
     );
     Notify(
     "Record overwritten",
     NotificationType.Warning
     )
     );
     Navigate('Gallery Screen');
    )

     

    ^Here I've just combined my With(...) and the modified If(...) function from @mmbr1606

    Hopefully this should work!

     

    Let me know!

  • FR-27081326-0 Profile Picture
    82 on at

    Hello @madlad & @mmbr1606!

    Thanks for yours avalability!


    It does not work because if the same user inserts two equal records (same combination of quarter and month), he should overwrite them and instead creates two different records.

    Instead it works in the case of equal records created by different users, because it does not overwrite them.


    It should be integrated to the code I pasted at the beginning (it overwrites the equal records created by the same user, but also the equal records created by different users).

    Thanks

  • madlad Profile Picture
    2,637 Moderator on at

    @Fe3 

    It looks like I mistakenly put the wrong column name above - could you try putting this in my previous code:

     

     

    _get_record: LookUp(
     Chargeability_New,
     Month.Value = DataCardValue8_1.Selected.Value && 
     Quarter.Value = DataCardValue8.Selected.Value &&
     'Created By'.Email = User().Email
     )

     

     

    ^Hopefully it's just that I mistakenly used CreatedBy instead of 'Created By'

     

    If that still fails, could you verify that the automatically generated 'Created By' column on your SP list looks correct? You may have to unhide it on sharepoint.

     

    Let me know

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard