web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Creating a form and pa...
Power Apps
Answered

Creating a form and pass through a foreign key

(0) ShareShare
ReportReport
Posted on by 90

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

Categories:
I have the same question (0)
  • Verified answer
    RusselThomas Profile Picture
    4,014 on at

    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

  • DaynaLitherland Profile Picture
    90 on at

    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'? 

  • RusselThomas Profile Picture
    4,014 on at

    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 🙂

  • DaynaLitherland Profile Picture
    90 on at

    Perfect, thanks again Russel. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard