cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Philipp-Peter
New Member

How to Relate this two Patch functions ?

Hello, 

 

I want to know how i can relate this to Patch functions ? 

 

Patch(Reservierungs;Defaults(Reservierungs); {StartDatum: StartDatum_DataCard2.Update; EndDatum: EndDatum_DataCard2.Update; 'Personen anzahl': 'Personen anzahl_DataCard2'.Update});;Patch(Kundes;Defaults(Kundes); {Vorname: Vorname_DataCard1.Update;Nachname: Nachname_DataCard1.Update;Telefon: Telefon_DataCard1.Update;'E-Mail': 'E-Mail_DataCard1'.Update});;Navigate(Screen1)

 

can you please help me if you need something else please ask questions.

 

With best reagards

Philipp Peter

3 REPLIES 3
LaurensM
Memorable Member
Memorable Member

Hi @Philipp-Peter 

 

Why would you like to relate the patch functions? Does one of the 2 tables contain a Look Up in which you would like to add the recently created record of the other table?

In this case you can save a created record by encapsulating the patch in a variable (which you can later use in a LookUp column):

Set(varName, Patch(YourPatchValues))


I hope this helps!

Philipp-Peter
New Member

Explanation:

I have two tables
Table 1 Customer
Table 2 Reservations

Lookup column: CustomerID

Between these tables I have now created a relationship with the column CustomerID which is in the table Reservations.

Now I want to use the patch function to put new data via Power Apps into the reservation table but also into the customer table.

The scenario is like this:

1. customer goes into the app and creates a new customer in the customer table in the customer table a customer ID is generated.
2. customer creates a reservation in the app in the reservation table, in the reservation table the allocation to the previously created customer should happen but I haven't come up with an idea yet.

I thought I needed the "Relate" function for this, but maybe it works without it?

My question is how can I create the relation to the previously created customer via the "Patch" function?

Code at this time (Writes only the date but does not establish a relationship):
________________________________
Patch(
Reservation;
Defaults(Reservation);
{
StartDate: StartDate_DataCard2.Update;
EndDate: EndDate_DataCard2.Update;
'Number of persons': 'Number of persons_DataCard2'.Update;
}
);;
Patch(
Customers;
Defaults(Customers);
{
First Name: FirstName_DataCard1.Update;
Surname: LastName_DataCard1.Update;
'Phone': 'Phone_DataCard1.Update;
'Email': 'Email_DataCard1'.Update
}
);;
ResetForm(Form3);;
ResetForm(Form4);;
Navigate(Screen1)
________________________________

LaurensM
Memorable Member
Memorable Member

@Philipp-Peter the relate() function I mainly use in many-to-many relationships.

In this case I would use the following code to achieve your goal:

(1) First Patch your customer and save the record in a variable

Set(varName,
Patch(
Customers;
Defaults(Customers);
{
First Name: FirstName_DataCard1.Update;
Surname: LastName_DataCard1.Update;
'Phone': 'Phone_DataCard1.Update;
'Email': 'Email_DataCard1'.Update
}
)
);;

You might need to change varName, to varName; (I am not familiar with the ; and ;; syntax)

(2) Now that you saved the customer record in the variable, you can use it in the reservation patch:

Patch(
Reservation;
Defaults(Reservation);
{
StartDate: StartDate_DataCard2.Update;
EndDate: EndDate_DataCard2.Update;
'Number of persons': 'Number of persons_DataCard2'.Update;

CustomerLookUp: varName
}
);;

I hope this helps!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,249)