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 / To prevent the inserti...
Power Apps
Answered

To prevent the insertion of duplicate records in a form; if a record that is already present is entered, replace it with the one already inserted.

(1) ShareShare
ReportReport
Posted on by 69

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.

 

In summary, for each combination of Quarter and Month, there should be only one value of 'Rec'.

 

The fields in the SharePoint list are: "Title" (User().FullName), "Month" (choice), "Quarter" (choice), "Rec" (number).

 

Can someone help me?

Thank you very much.

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @Fe3 - are you leveraging an EditForm control or submitting your data back using a Patch function?

  • FR-27081326-0 Profile Picture
    69 on at

    I currently use an edit form. I also tried to use a path function but I can’t implement it yet.


    Can you recommend something?

  • Verified answer
    Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @Fe3 - see example below:

     

    With(
     {
     _get_record: LookUp(
     'Your List',
     Month.Value = Dropdown1.Selected.Value && Quarter = Dropdown2.Selected.Value
     )
     },
     If(
     IsBlank(_get_record),
     Patch(
     'Your List',
     Defaults('Your List'),
     Form1.Updates
     ),
     Patch(
     'Your List',
     _get_record,
     Form1.Updates
     );
     Notify(
     "Existing record ovewritten",
     NotificationType.Warning
     ) // optional
     )
    )

     

    Note the above uses dropdown controls as an example. You will need the replace the controls with whatever you're using to identify the Month and Quarter.

     

  • FR-27081326-0 Profile Picture
    69 on at

    Hi @Amik !
    Your solution has been very useful and works.


    I have another question. How do I view the names of all users who enter a record through the app?

    I tried the User () feature. Full Name, but since I am the owner of the app, I see all the records with my name.

     

    Additionally, I would like to view all the records but allow editing only for the user who created the record.


    How can I fix it?

  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @Fe3 -

     

    I have another question. How do I view the names of all users who enter a record through the app?

     

    Simplest option is to create a Gallery control, insert a Label control into that Gallery, and on the Text property of that Label, enter:

     

    ThisItem.'Created By'.DisplayName

     

    Additionally, I would like to view all the records but allow editing only for the user who created the record.

     

    The answer would depend on how your user is going to access that record in the first place because there are      many answers to this. As a basic example, suppose the user is accessing a record from a Gallery control, you could run a condition to set the Form Mode to View if the user selected an item they did not create, otherwise set the Form to Edit. For example, on the OnSelect property of the Gallery control, use:

     

    If(ThisItem.'Created By'.Email = User().Email,
     EditForm(Form1),
     ViewForm(Form1)
     )
  • FR-27081326-0 Profile Picture
    69 on at

    Hi @Amik !

    Thanks for your availability!
    I have one last question.

    I have this code in the on select of the send button to submit the form.

    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')

    )

     

    The goal should be to make sure that the user cannot choose two equal combinations of quarter and month; in this case, the record must be overwritten.

    This code works partly because it overwrites even when you choose the same combination of quarter and month of another user, instead in this case should leave it.


    So how could I modify it to make it overwrite the record if the user is the user(). full name and if there are two combinations of month and quarter while not overwrite it if the same combination run different users?

  • Ami K Profile Picture
    15,679 Super User 2024 Season 1 on at

    @Fe3 - please remember to accept the solution to the answer given to your new question. Regarding the other question, you will need to add another condition into the LookUp:

     

    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
     ),
     Patch(
     Chargeability_New,
     _get_record,
     Frm_Chargeability.Updates
     );
     Notify(
     "Record sovrascritto all'esistente",
     NotificationType.Warning
     )// optional
     );
     Navigate('Gallery Screen')
    )

     

     

     

     

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…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 368 Super User 2026 Season 1

#1
Kalathiya Profile Picture

Kalathiya 368 Super User 2026 Season 1

#3
WarrenBelz Profile Picture

WarrenBelz 318 Most Valuable Professional

Last 30 days Overall leaderboard