cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KCh
Level: Powered On

How to add data to existing Entity from the Canvas' form?

Hi,

 

I'm sure I'm missing a very simple answer..

 

I Have two Entities: "A" and "B".

I have a Gallery on my Canvas app. In this Gallery there are a number of fields from Entity "A" (all in View Mode) and one Text Input field (Edit Mode).

Also I have a Button.

User can see field from Entity "A" and put any information into Text Input field for each row. Then he should press the Button.

I woul like to create a new row in Entity "B" and save all data from the screen:

- data from field from Entity "A";

- data that User put into Text Input fields.

 

What formula should I use for my Button the realize this?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft v-siky-msft
Microsoft

Re: How to add data to existing Entity from the Canvas' form?

Hi @KCh ,

 

You need to patch a record of related entity to the Aspect_score field:

 ForAll(Gallery_Aspects.AllItems,Collect(Col_GalleryData,{A:Label_Aspect.Text,B:Score_Number.Text})); ForAll(Col_GalleryData, Patch(Score_v1, Defaults(Score_v1),{Aspect_score: LookUp(Aspect_v1, RelatedColumn= A) , Score_Text: Value(B)} ))

Note: please replace the RelatedColumn to fit your app.

Best regards,

Sik

View solution in original post

11 REPLIES 11

Re: How to add data to existing Entity from the Canvas' form?

Hi!

 

If you have your button within the gallery, you can simply use the Patch function to achieve this using this formula: 

 

Patch(TableB;Defaults(TableB);ThisItem)

 

You can read about the Patch function if you go to this link https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch

BR

Pontus

KCh
Level: Powered On

Re: How to add data to existing Entity from the Canvas' form?

Hi!

 

I'm not sure that I have my button within the gallery, because "ThisItem" doesn't available when I try to use such formula..

I put sepaarte a gallery and a button. Gallery is connected with the Entity "A" from Common Data Model. I need to create a new row in Entity "B" by pressing the button.

Re: How to add data to existing Entity from the Canvas' form?

Hi!

 

Alright, I see. Well, do you want to create a new record in Entity B for every record in Entity A, you can use the following formula in OnSelect property of the button: 

 

ForAll(TableA;Patch(TableB;Defaults(TableB);{name:name;number:number}))

 

Just replace name and number to your own field names. 

BR

Pontus

Microsoft v-siky-msft
Microsoft

Re: How to add data to existing Entity from the Canvas' form?

Hi @KCh ,

 

I think you should first to collect all the data shown in the gallery to a collection because there is a empty text input box, then patch the collection to entity B.

 

ForAll(Gallery1.AllItems,Collect(Col_GalleryData,{A:Title1.Text,B:TextInput1.Text})); ForAll(Col_GalleryData, Patch(EntityB, Defaults(EntityB),{Field1:A, Field2: B} ))

 

Note: Title1 and TextInput1 is the field control name, not the field name.

Best regards,

Sik

KCh
Level: Powered On

Re: How to add data to existing Entity from the Canvas' form?

Thanks to all for the replies! 🙂

 

@v-siky-msft Thank you very much! Yes, I heed to collect first. Now all is work perfect for all TEXT fields, but I have 2 errors for 2 fields:

errors.png

 

 

 

 

 

 

Could you please advise how can I save these types of records?

KCh
Level: Powered On

Re: How to add data to existing Entity from the Canvas' form?

For the second error I found a solution - just add Value in the Patch:

 

ForAll(Gallery1.AllItems,Collect(Col_GalleryData,{A:Title1.Text,B:TextInput1.Text})); ForAll(Col_GalleryData, Patch(EntityB, Defaults(EntityB),{Field1:A, Field2: Value(B)} ))

 

 

 

Microsoft v-siky-msft
Microsoft

Re: How to add data to existing Entity from the Canvas' form?

What are the date types of these two columns? Can you share the formula you are using?

Best regards,

Sik

KCh
Level: Powered On

Re: How to add data to existing Entity from the Canvas' form?

The formula is:

 

 

ForAll(Gallery_Aspects.AllItems,Collect(Col_GalleryData,{A:Label_Aspect.Text,B:Score_Number.Text})); ForAll(Col_GalleryData, Patch(Score_v1, Defaults(Score_v1),{Aspect_score:A, Score_Text: Value(B)} ))

 

 

 

Label_Aspect is a label where I show information from the Entity "Aspects_v1".

In the Entitiy "Score_v1" I have a field "Aspect_score". Its' data type is Lookup:

Aspect_score.png

 

 
Microsoft v-siky-msft
Microsoft

Re: How to add data to existing Entity from the Canvas' form?

Hi @KCh ,

 

You need to patch a record of related entity to the Aspect_score field:

 ForAll(Gallery_Aspects.AllItems,Collect(Col_GalleryData,{A:Label_Aspect.Text,B:Score_Number.Text})); ForAll(Col_GalleryData, Patch(Score_v1, Defaults(Score_v1),{Aspect_score: LookUp(Aspect_v1, RelatedColumn= A) , Score_Text: Value(B)} ))

Note: please replace the RelatedColumn to fit your app.

Best regards,

Sik

View solution in original post

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,868)