cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Oliclusive
Helper I
Helper I

Patch function not working

Hi Community,

 

it is my first time I use the Pacth function and it seems like I don't really understand how the function can be used to Step 3) of the following scenario :

 

1) Select a List item in a Gallery > Selected Item is Stored in a Collection "Selection_Open" > Navigate to an Edit Form (OK)

2) Make a manual selection in a Dropdown for the item to add the "reasoncode" > "Stillstandsklassen_Open.SelectedText" (OK)
3) Save the selected Text from Dropdown back to the SQL table for the selected item (the one selected in Step 1 from the Gallery) > error "reasoncode" field is not found (maybe Syntax error?)

 

I just cant get the Patch function for 3) to work

 

Attached you find the screenshots, any help from a Pro user is appreciated a lot

 

Thanks

Oli

1 ACCEPTED SOLUTION

Accepted Solutions

If you are adding new entries, use Defaults in the Patch:

Patch('[dbo].[Werma_DowntimeSlaveData]';Defaults('[dbo].[Werma_DowntimeSlaveData]');
{reasoncode: Stillstandsklassen_Open.SelectedText.Value})
;;
Back(ScreenTransition.Fade);;

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

View solution in original post

13 REPLIES 13
gabibalaban
Dual Super User
Dual Super User

I took a fugitive look to your code ... The are some {....} missing.

 

The correct format of patch function is:

Patch ( source, record, {name of element: the new value of element, ...}). 

eka24
Super User
Super User

Few questions:

1. What column in the SQL Table are you patching to, Selection_Open or reasoncode

2. Are you patching from a collection or directly from your form

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Thanks for noticing - I added them but still no luck, see attached (Erro says "function Patch with invalid arguments")

Patch(
'[dbo].[Werma_Downtime_7days]';
Selection_Open;
{reasoncode: Stillstandsklassen_Open.SelectedText})
;;
Back(ScreenTransition.Fade);;

Hi, I want to overwrite the entry in Column "reasoncode"

 

I use this function to set the selection from the gallery for "Selection_Open":

 

Set(Selection_Open;Gallery_NonProductive_States_Open.Selected)
 
 

see another screenshot attached, hope it makes it more clear?

 

 
Please what is Selection_Open and reasoncodeare they all column names?
Patch(
'[dbo].[Werma_Downtime_7days]';
Selection_Open;
{reasoncode: Stillstandsklassen_Open.SelectedText.Value})
;;
Back(ScreenTransition.Fade);;
 
 
Try:
Patch(
'[dbo].[Werma_Downtime_7days]';
{reasoncode: Stillstandsklassen_Open.SelectedText})
;;
Back(ScreenTransition.Fade);;
 

@Oliclusive 

As I can see.... 

Selection_Open is a selected item from a gallery.

reasoncode is a column of type varchar (or similar) from one SQL Table and

Stillstandsklassen_Open is a dropdown control (Stillstandsklassen_Open.SelectedText is not a string, it is a record value, so doesn't match with reasoncode).

So,

the wrong part is ,as @eka24 wrote before, Stillstandsklassen_Open.SelectedText. The correct form is Stillstandsklassen_Open.SelectedText.Value (or you can choose a column containing the desired value). 

Please keep in mind that if the source of your dropdown control is a collection, then you can refer inside the Stillstandsklassen_Open.SelectedText to column showed in dropdown or to another column from the selected record. 

 

Hope it helps !

 

 

 

Hi, thanks a lot so I changed the code a bit:
---

Patch(
'[dbo].[Werma_Downtime_7days]'.reasoncode;
//Selection_Open;
{reasoncode: Stillstandsklassen_Open.SelectedText.Value})
;;
Back(ScreenTransition.Fade);;
----
This one does not give me any errors in the designer but unfortunately "reasoncode" is still not written back to the SQL (no error banner shown, no success banner shown, no data entered in SQL, jut screen transition happening).

Thanks a lot for your help so far - I think we are getting close 😉
Oli

Try:
Patch('[dbo].[Werma_Downtime_7days]',{reasoncode: Stillstandsklassen_Open.SelectedText.Value});;
Back(ScreenTransition.Fade);;

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Hi @eka24,

this code gave me the error "no acess to write/ Primary Key does not exist" so I realized that I was pointing to a View and not the actual SQL table - now I changed to:

Patch(
'[dbo].[Werma_DowntimeSlaveData]';
{reasoncode: Stillstandsklassen_Open.SelectedText.Value})
;;
Back(ScreenTransition.Fade);;

Result: no error in designer but when I try it in the app still nothing but the screen transition happens. It does not update the selected item from the gallery with the selected reasoncode.

Any clues what I could do to investigate that behavior further?

Thanks

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.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,622)