cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Dkerr
New Member

Prevent Duplicate Inserts During a Patch in Button's OnSelect

I have a Sharepoint list in which one of the items is a date field. 

The entry should be the first day of the month as I am using it for setting goals for the month.  

I assume there is some way to validate that the user entered:

"month"/01/"year"

 

as well I want to either on entry of the date check to see if there is a record with the same date to avoid a duplicate record or at the least upon submittal check and not add the record.

 

I am new to PowerApps and not sure how to do figure out this quickly.  I looked at Patch but I am not sure that is what I want.

Any help would be appreciated.  

1 ACCEPTED SOLUTION

Accepted Solutions
mr-dang
Community Champion
Community Champion


@Dkerr wrote:

I have a Sharepoint list in which one of the items is a date field. 

The entry should be the first day of the month as I am using it for setting goals for the month.  

I assume there is some way to validate that the user entered:

"month"/01/"year"


 

I would recommend that you have PowerApps choose this automatically for your user. You can do this by adding a DatePicker control, setting its DisplayMode to Disabled, and setting its Default date to:

Date(Year(Today()),Month(Today()),1)

This means the default date will be equal to this year, the current month, and the first day of the month. Revise the blue part if you want the user to choose a different month.

powerapps set default date.png

 


@Dkerr wrote:

 

as well I want to either on entry of the date check to see if there is a record with the same date to avoid a duplicate record or at the least upon submittal check and not add the record.


 

You can use a condition to perform or not perform an action:

If(IsEmpty(Filter(datasource,date=DatePicker1.SelectedDate)),
    Patch(datasource,Defaults(datasource),
        {date: DatePicker1.SelectedDate,
            field2: data2,
            field3: data3
        }
    )
)

The condition means, "As long as there is no record in the datasource where the date is equal to the Default date described above (or literally as long as the filter is empty), write a new record with that determined date and other data."

 

Microsoft Employee
@8bitclassroom

View solution in original post

3 REPLIES 3
mr-dang
Community Champion
Community Champion


@Dkerr wrote:

I have a Sharepoint list in which one of the items is a date field. 

The entry should be the first day of the month as I am using it for setting goals for the month.  

I assume there is some way to validate that the user entered:

"month"/01/"year"


 

I would recommend that you have PowerApps choose this automatically for your user. You can do this by adding a DatePicker control, setting its DisplayMode to Disabled, and setting its Default date to:

Date(Year(Today()),Month(Today()),1)

This means the default date will be equal to this year, the current month, and the first day of the month. Revise the blue part if you want the user to choose a different month.

powerapps set default date.png

 


@Dkerr wrote:

 

as well I want to either on entry of the date check to see if there is a record with the same date to avoid a duplicate record or at the least upon submittal check and not add the record.


 

You can use a condition to perform or not perform an action:

If(IsEmpty(Filter(datasource,date=DatePicker1.SelectedDate)),
    Patch(datasource,Defaults(datasource),
        {date: DatePicker1.SelectedDate,
            field2: data2,
            field3: data3
        }
    )
)

The condition means, "As long as there is no record in the datasource where the date is equal to the Default date described above (or literally as long as the filter is empty), write a new record with that determined date and other data."

 

Microsoft Employee
@8bitclassroom

View solution in original post

Many thanks for such a quick answer and clear explanation.  I really appreciate it!

David

@mr-dang 

Is there a way to apply this to a forall on a local collection?

 

We are working on a an qr scanner app where you can scan items to a collection. Then when you have collected all your data you can patch the items to a sharepoint list.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (46,986)