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 / How to filter duplicat...
Power Apps
Unanswered

How to filter duplicates from the sharepoint list and generate an alert if any duplicate found

(1) ShareShare
ReportReport
Posted on by 36

Hi All,

 

I have built an application which has a form with few fields with one of the fields as primary(This entry has to be unique).I have added a logic on form submission, that if on filtering the data source, system finds the value entered on the primary field, A pop up message mentioning it's a duplicate record should come up.

How I did it.

1. Created an alert , it's visibility is based on a variable. Only when the variable is set to true the alert should come up. On app load, the variable should default to false.

2. On form submit. Filter whether the entered value matches the data source, If it does not update the visibility of the variable to true.

 

The problem is when I try submitting form first time after entering duplicate record, it does not show the alert message. the value of the variable is not set to true. On submitting again it works fine.

Any suggestions why it does not work 1st time?

 

 

 

 

Categories:
I have the same question (0)
  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    hey @PriyankaBhatt ,

     

    can you share the code that you've used? 

     

  • PriyankaBhatt Profile Picture
    36 on at

    If(
    !IsEmpty(
    Filter(
    SharepointList,
    PrimaryControl.Text='ColumnNamefromSharepoint'
    )
    ),
    Notify("If was executed",NotificationType.Warning);UpdateContext({Variable: true}),
    If(
    (form.Mode = FormMode.New),
    Set(
    VarLastSubmit,
    Patch(
    SharepointList,
    Defaults(SharepointList),
    form.Updates,
    'form2'.Updates
    )
    );
    ResetForm(form);
    UpdateContext(
    {
    editMode: false,
    newMode: false
    }
    );Notify("Else-If was executed",NotificationType.Warning),
    Patch(
    SharepointList,
    Gallery.Selected,
    form.Updates,
    'form2'.Updates
    );
    ResetForm(form);
    UpdateContext(
    {
    editMode: false,
    newMode: false
    }
    );Notify("Else-Else was executed",NotificationType.Warning)
    )
    );

     

     

    I have added some notification for myself to understand which part of the loop is running. Will remove them when my function starts working.

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    Can you try this:

    If(
     CountRows(
     Filter(
     SharepointList,
     PrimaryControl.Text='ColumnNamefromSharepoint'
     ))>0
     ),
     Notify(
     "If was executed",
     NotificationType.Warning
     );
     UpdateContext({Variable: true}),
     If(
     (Form.Mode = FormMode.New),
     Set(
     VarLastSubmit,
     Patch(
     SharepointList,
     Defaults(SharepointList),
     form.Updates,
     'form2'.Updates
     )
     );
     ResetForm(form);
     UpdateContext(
     {
     editMode: false,
     newMode: false
     }
     );
     Notify("Else-If was executed",NotificationType.Warning),
     Patch(
     SharepointList,
     Gallery.Selected,
     form.Updates,
     'form2'.Updates
     );
     ResetForm(form);
     UpdateContext(
     {
     editMode: false,
     newMode: false
     }
     );
     Notify("Else-Else was executed",NotificationType.Warning)
     )
    );

     

    I don't really understand the way you are using Patch combined with Forms.

    It would be easier to use SubmitForm(Form). The form will automaticlly check if it's in FormMode.New or Edit and map the changes to the record used in the form.

     

  • PriyankaBhatt Profile Picture
    36 on at

    Still Same issue. It does not work on first click. Works fine second click onwards.

     

    I have 2 forms on the same screen. Hence had to use patch instead on Submit. With submit, data from one form was being submitted to the datasource.

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    Why don't you use SubmitForm twice? 

    SubmitForm(Form1);
    SubmitFrom(From2)

     

    It seems to me, that the values are not exactly the same when the notification comes only after you save it the Second time. 

     

    Have you checked with a label if the Values are equal? 

    you could use something like this

    If(CountRows(
     Filter(
     SharepointList,
     PrimaryControl.Text='ColumnNamefromSharepoint'
     ))>0,
     "Exists","Does not exist"
    )

     

  • PriyankaBhatt Profile Picture
    36 on at

    The first If statement is being Run, I am getting the warning message that's part of the if function, only thing, the variable context is not set to true first time and changing only in second attempt.

     

    On Form Submit: If I submit both the forms it will create 2 entries in the sharepoint list.

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    Okay now I get it. 

    If(
     CountRows(
     Filter(
     SharepointList,
     PrimaryControl.Text='ColumnNamefromSharepoint'
     ))>0
     ),
     Notify(
     "If was executed",
     NotificationType.Warning
     );
     Set(Variable, true),
     If(
     (Form.Mode = FormMode.New),
     Set(
     VarLastSubmit,
     Patch(
     SharepointList,
     Defaults(SharepointList),
     form.Updates,
     'form2'.Updates
     )
     );
     ResetForm(form);
     Set(editMode, false);
     Set(newMode, false);
     Notify("Else-If was executed",NotificationType.Warning),
     Patch(
     SharepointList,
     Gallery.Selected,
     form.Updates,
     'form2'.Updates
     );
     ResetForm(form);
     Set(editMode, false);
     Set(newMode, false);
     Notify("Else-Else was executed",NotificationType.Warning)
     )
    );

     

    Can you try the Set function instead of the UpdateContext just to test it. 

     

  • PriyankaBhatt Profile Picture
    36 on at

    No Luck! With Set function I don't see the Alert at all. 

    I just noticed that with update context, on First click attempt-my alert message is coming up for microseconds and disappears on their own.

    With Second click it remains how it supposed to be.

  • Daniel Bocklandt Profile Picture
    5,099 Super User 2025 Season 2 on at

    So you would say it is acting like a second Button would be clicked somewhere else?
    Is the new Record still saved or does the function Block that action successfully? 

    Otherwhiseyou could put the updatecontext Function earlier in the controll that gets checked. You would just need to put the function in OnChange, and put delay output to true.

    If(
     CountRows(
     LookUp(
     SharepointList,
     PrimaryControl.Text='ColumnNamefromSharepoint'
     ))>0,
     Notify(
     "If was executed",
     NotificationType.Warning
     );
     UpdateContext({Double: true}),
    UpdateContext({Double: false}))

     

    and in your button just like this: 

    If(Double,UpdateContext({Variable:true}),UpdateContext({Variable:false});
    If(
     (Form.Mode = FormMode.New),
     Set(
     VarLastSubmit,
     Patch(
     SharepointList,
     Defaults(SharepointList),
     form.Updates,
     'form2'.Updates
     )
     );
     ResetForm(form);
     Set(editMode, false);
     Set(newMode, false);
     Notify("Else-If was executed",NotificationType.Warning),
     Patch(
     SharepointList,
     Gallery.Selected,
     form.Updates,
     'form2'.Updates
     );
     ResetForm(form);
     Set(editMode, false);
     Set(newMode, false);
     Notify("Else-Else was executed",NotificationType.Warning)
     )
    );

     

    and try to create all your variables earlier before you need them. You could Create them OnVisible of the Screen all as false. 

     

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…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard