cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aboucher
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

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

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
PavanKumar
Responsive Resident
Responsive Resident

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
Pstork1
Dual Super User
Dual Super User

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.
aboucher
Frequent Visitor

 


@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.


@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?

PavanKumar
Responsive Resident
Responsive Resident

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


@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()})

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.
aboucher
Frequent Visitor


@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})
aboucher
Frequent Visitor

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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,762)