cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

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
Highlighted
Community Support
Community Support

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

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

Highlighted
Helper III
Helper III

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.

Highlighted
Resolver IV
Resolver IV

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

Highlighted
Community Support
Community Support

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

Highlighted
Helper III
Helper III

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?

Highlighted
Helper III
Helper III

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

 

 

 

Highlighted
Community Support
Community Support

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

Highlighted
Helper III
Helper III

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

 

 
Highlighted
Community Support
Community Support

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
Check this Out

Announcing

Class of 2020- Season 2

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,643)