cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Patch function not working

Hello,

 

I am having trouble getting my Patch functions to work.  I have tried many different things I have read in forums including replacing the comas with semicolons, changing the variables to values, and removing the braces.  No matter what it says "The function 'Patch' has some invalid arguments. Here is the code: 

 

Patch(tblPass, First( Filter(tblPass,'Created By'.DisplayName = CurrentUser.DisplayName, Returned = false)), {tblPass.'Time Returned' : TimeNow})

// The declarations below are elsewhere in the app. I include just to show where the variables are coming from.
Set(CurrentUser,Office365Users.MyProfile())
Set(TimeNow,Now())
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Dual Super User
Dual Super User

Re: Patch function not working

The single quotes are there because the field name has a space in it.

 

I've duplicated your TimeNow variable and am able to save it without an issue.  But I don't have the Returned field in my test.  Is that a Yes/No column?

 

Here's the formula that is working for me.

Patch('Attendees List', First( Filter('Attendees List','Created By'.Email = User().Email)), { LastVisit: TimeNow})

'Attendees list' is a SharePoint list and LastVisit is a DateTime column.  I'm using Email because it is more unique than display name, but the concept is the same.  You really don't need to retrieve the profile, just use User() which is the current user.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Highlighted
Dual Super User
Dual Super User

Re: Patch function not working

Add semicolons to the end of each code line

code;
patch();
code;

Of course the actual character used may vary if you are international.  Check you localization settings.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

10 REPLIES 10
Highlighted
Responsive Resident
Responsive Resident

Re: Patch function not working

Hi, Give a try with the following expression and let me know if you still facing any issues. ClearCollect(colTblPass,First( Filter(tblPass,'Created By'.DisplayName = CurrentUser.DisplayName, Returned = false))); Patch(tblPass, First(colTblPass), {'Time Returned' : TimeNow}) ------------------------------------------------------------------------------------------- if this answers your question mark it as verified and give it a thumbsup Regards, Pavan Kumar Garlapati
Highlighted
Dual Super User
Dual Super User

Re: Patch function not working

I see two potential issues

1) When setting the value tblPass.'Time Returned' you don't need tblPass that is implied by the fact taht you are patching tblPass.  There is no way to patch a record from a different table.

2) TimeNow will be a timespan variable.  Depending on what type of field Time Returned is you probably need to surround that value with some kind or reformatting to cast it to the appropriate data type. 

 

I suspect your error is coming from #2.  What data type is the field you are patching?



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Highlighted
Frequent Visitor

Re: Patch function not working

 


@Pstork1 wrote:

I see two potential issues

1) When setting the value tblPass.'Time Returned' you don't need tblPass that is implied by the fact taht you are patching tblPass.  There is no way to patch a record from a different table.

2) TimeNow will be a timespan variable.  Depending on what type of field Time Returned is you probably need to surround that value with some kind or reformatting to cast it to the appropriate data type. 

 

I suspect your error is coming from #2.  What data type is the field you are patching?



It is a date and time field in a SharePoint list.

Highlighted
Frequent Visitor

Re: Patch function not working


@PavanKumar wrote:
Hi, Give a try with the following expression and let me know if you still facing any issues. ClearCollect(colTblPass,First( Filter(tblPass,'Created By'.DisplayName = CurrentUser.DisplayName, Returned = false))); Patch(tblPass, First(colTblPass), {'Time Returned' : TimeNow}) ------------------------------------------------------------------------------------------- if this answers your question mark it as verified and give it a thumbsup Regards, Pavan Kumar Garlapati

When you say "colTblPass" should that be replaced with the column name of the table tblPass?

Highlighted
Responsive Resident
Responsive Resident

Re: Patch function not working

Yes please also in the Time returned (i believe its a date field? if yes then use Today() Regards, Pavan Kumar Garlapati
Highlighted
Frequent Visitor

Re: Patch function not working


@PavanKumar wrote:
Yes please also in the Time returned (i believe its a date field? if yes then use Today() Regards, Pavan Kumar Garlapati

Below is the code I am using.  I am now getting invalid argument type on both formulas.  I have tried it both with and without the single quotes.  The Time Returned field is a date time field.  I am more concerned with the time in that field than the date.  

ClearCollect('Time Returned',First( Filter(tblPass,'Created By'.DisplayName = CurrentUser.DisplayName, Returned = false)));  Patch(tblPass, First('Time Returned'), {'Time Returned' : Today()})
Highlighted
Dual Super User
Dual Super User

Re: Patch function not working

The single quotes are there because the field name has a space in it.

 

I've duplicated your TimeNow variable and am able to save it without an issue.  But I don't have the Returned field in my test.  Is that a Yes/No column?

 

Here's the formula that is working for me.

Patch('Attendees List', First( Filter('Attendees List','Created By'.Email = User().Email)), { LastVisit: TimeNow})

'Attendees list' is a SharePoint list and LastVisit is a DateTime column.  I'm using Email because it is more unique than display name, but the concept is the same.  You really don't need to retrieve the profile, just use User() which is the current user.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Highlighted
Frequent Visitor

Re: Patch function not working


@Pstork1 wrote:

The single quotes are there because the field name has a space in it.

 

I've duplicated your TimeNow variable and am able to save it without an issue.  But I don't have the Returned field in my test.  Is that a Yes/No column?

 

Here's the formula that is working for me.

Patch('Attendees List', First( Filter('Attendees List','Created By'.Email = User().Email)), { LastVisit: TimeNow})

'Attendees list' is a SharePoint list and LastVisit is a DateTime column.  I'm using Email because it is more unique than display name, but the concept is the same.  You really don't need to retrieve the profile, just use User() which is the current user.


Yes, the Returned field is a Yes/No Column.  Here is the slightly modified version of your code that I am using.  I am getting "Invalid Argument Type".  Just for kicks, I also tried removing the Returned = false, and there was no change in the error.

Patch(tblPass, First(Filter(tblPass, 'Created By'.DisplayName = CurrentUser.DisplayName, Returned = false)), {'Time Returned' : TimeNow})
Highlighted
Frequent Visitor

Re: Patch function not working

Well, I figured out the issue.  I had more code attached to this button.  

<code> &
Patch(...) &
<code>

Does anyone know how to successfully execute another procedure on this button click?

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (10,242)