cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KCh
Advocate II
Advocate II

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
v-siky-msft
Community Support
Community Support

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
pontusofsweden
Resolver IV
Resolver IV

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

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.

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

v-siky-msft
Community Support
Community Support

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

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
Advocate II
Advocate II

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

 

 

 

v-siky-msft
Community Support
Community Support

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

Best regards,

Sik

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

 

 
v-siky-msft
Community Support
Community Support

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (3,040)