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

Creating a form and pass through a foreign key

Hello All,

 

I am exceptionally new to all things PowerApps, and decided to have a go at creating something today... So I'm sure this will be the first question of many!

 

I've created a blank canvas, and provided four tables as my data source:

Header

MessageDetails

ApprovalDetails

Implementation

 

I've got a homescreen with a gallery control which loads content from the Header table. I've then got a screen with two edit forms, one for the Header, and one for the MessageDetails. On the SQL database, the Header has a PK of 'Id' with the appropriate Identity Specification, and on the MessageDetails, I have a field called 'HeaderId' which has a relationship to the Header table. All good so far.

 

On my Save Button, I've got the following:

SubmitForm(HeaderDetailForm);SubmitForm(MessageDetailForm);Navigate(Homepage,ScreenTransition.None)

 

However, all it does it go to 'Getting data ready ....' but does create the records. Just doesn't return to the homepage. 

 

As a test, I've duplicated my screen and deleted the MessageDetailForm, and the save button works correctly (i.e. returns to the homepage) with the following:

SubmitForm(HeaderDetailForm);Navigate(Homepage,ScreenTransition.None)

 

So I presume I've done something wrong by submitting the two forms. I can't help but feel I need to pass through the PK from header into the FK field on Message Details. How do I do this?

 

Any help you can offer in getting the two forms to submit, and passing through the FK, would be greatly appreciated.

 

Kind Regards,

Dayna

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Creating a form and pass through a foreign key

Hi DaynaLitherland,

 

In the case of submitting a new entry, it would make sense to pass the key of the parent item to the related item.

To do this, you can use a combination of the OnSuccess: property of the first form and its LastSubmit property.

 

When a form is submitted, the resulting row of data that is stored in the source, (not submitted, but actually stored, including any columns autocompleted by the source), is returned to PowerApps and stored in the LastSubmit property of the form, which is accessible via the forms OnSuccess: property. 

 

So in your example, if you add a record to the Header table using the HeaderDetailForm form, the resulting row of data that SQL stores will be stored in HeaderDetailForm.LastSubmit.

You can get to the SQL generated primary key Id value by using HeaderDetailForm.LastSubmit.Id

 

To use this value in your next submission to the MessageDetailForm, you would need to place the PK Id value into the MessageDetailForm.HeaderID column prior to submitting the form.  This means you need to chain the submissions, ensuring the Header table is successfully updated first before submitting the MessageDetailForm

 

So - your first submit button for the HeaderDetailForm will look like this;

Submit(HeaderDetailForm)

and that's it.  Then, use the OnSuccess: property to trigger your next submission as follows;

Submit(MessageDetailForm)

Lastly, on your MessageDetailForm, you need to set the Default property of your HeaderID field to;

HeaderDetailForm.LastSubmit.Id

Hope this helps,

 

Kind regards,

 

RT

View solution in original post

4 REPLIES 4
Highlighted
Microsoft
Microsoft

Re: Creating a form and pass through a foreign key

Hi DaynaLitherland,

 

In the case of submitting a new entry, it would make sense to pass the key of the parent item to the related item.

To do this, you can use a combination of the OnSuccess: property of the first form and its LastSubmit property.

 

When a form is submitted, the resulting row of data that is stored in the source, (not submitted, but actually stored, including any columns autocompleted by the source), is returned to PowerApps and stored in the LastSubmit property of the form, which is accessible via the forms OnSuccess: property. 

 

So in your example, if you add a record to the Header table using the HeaderDetailForm form, the resulting row of data that SQL stores will be stored in HeaderDetailForm.LastSubmit.

You can get to the SQL generated primary key Id value by using HeaderDetailForm.LastSubmit.Id

 

To use this value in your next submission to the MessageDetailForm, you would need to place the PK Id value into the MessageDetailForm.HeaderID column prior to submitting the form.  This means you need to chain the submissions, ensuring the Header table is successfully updated first before submitting the MessageDetailForm

 

So - your first submit button for the HeaderDetailForm will look like this;

Submit(HeaderDetailForm)

and that's it.  Then, use the OnSuccess: property to trigger your next submission as follows;

Submit(MessageDetailForm)

Lastly, on your MessageDetailForm, you need to set the Default property of your HeaderID field to;

HeaderDetailForm.LastSubmit.Id

Hope this helps,

 

Kind regards,

 

RT

View solution in original post

Highlighted

Re: Creating a form and pass through a foreign key

Hi Russel,

 

Thank you for the comprehensive response, it really helped in trying to understand what I'm doing and why! 🙂


Much appreciated,

Dayna

 

P.S. Do you have any recommendation in material to start learning this in more detail, or just 'build one'? 

Highlighted
Microsoft
Microsoft

Re: Creating a form and pass through a foreign key

The guided learning on powerapps.com is really great, and this community provided me with practically everything else.

Besides that, building and learning was the best way for me 🙂

Highlighted

Re: Creating a form and pass through a foreign key

Perfect, thanks again Russel. 

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (11,112)