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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Data entry for child t...
Power Apps
Unanswered

Data entry for child table when the parent row hasn't been created yet

(0) ShareShare
ReportReport
Posted on by 219

I have a form where the user enters in information for an event (this will populate the parent SP list called eventList and have of course an ID value assigned when they hit submit).
Before they hit submit, one of the questions is around customers attending the event (which is a separate SP List called customerList).

That child SP list wants to know the parent.ID value when ultimately saved in SP.

But the order is such that the customerList doesn't know the eventList.ID until the form is submitted.

I have 3 questions...
1) what's the best way to store the customerList temporarily (do you simply keep it in a temp collection, or do you do save to the SP List without the eventList.ID value?)

2) how best to get the new eventList.ID back ... then...

3) patch in the eventList.ID into the customerList for each row and then store into the customerList SP site.

I know this is more strategy talk than a specific question but I suspect many of you have already been challenged with this same thing before.

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc1966 

    If your information is in a Gallery, then it is already available to you.  If it is in another form, then that too is available to you.

     

    What you need to do is, in the Parent Record Form, use the OnSuccess action to then write the Child records.

    In the OnSuccess you will have access to Self.LastSubmit (or yourForm.LastSubmit elsewhere) where you can get the ID.  ex.  Self.LastSubmit.ID

     

    So, if it is a gallery of child questions you have, then in your OnSuccess...something like this:

    Patch(yourChildList,
     ForAll(yourGallery.AllItems,
     {someColumn: controlValueName.Text,
     ...etc...,
     ParentID: Self.LastSubmit.ID
     }
     )
    )

    This will submit all of your gallery items as child records with the ParentID filled in.

     

    I hope this is helpful for you.

  • sasrsc1966 Profile Picture
    219 on at

    Region Capture.jpg

    I forgot to mention I'm not doing a Form submit but a patch ... I couldn't put multiple statements in the  If(isEmpty(Errors stmt... So after I added ...

     

    Set(varLastSumitID,Last('Ticket Request').ID);

     

    Then for the patch I think this should work but it doesn't...I turned the ForAll / Patch around... from what you said.

     

     // now submit customers 
     If(CountRows(colCustomers) > 0,
     ForAll(colCustomers, Patch(Customers,Defaults(Customers),{
     Name: Name,
     TicketRequestId: varLastSumitID
     }))
    
     );

     

    I've found a few examples where you've suggesting looping through the gallery but I want to use a collection instead. I'm still not quite right.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @sasrsc1966 

    First, I'd recommend a Form rather than a hand made patch formula.  It will make your PowerApp life simpler!

     

    However, if you are using a Patch statement for the Parent record, then that will already return the ID.  You need not spend any more time trying to get it from the list.

    i.e.  Set(varLastSubmitID, Patch(......).ID)

    If ID is blank, then it failed.  Otherwise it will return the ID.

    That can then be used in your other formula.  

    Your ForAll is backward - you are using it like a ForLoop in development.  It is not, it is a function that returns a table of records based on the schema you want. Using it like a ForLoop on the patch will cause your performance to suffer.

     

    Formula should be:

     // now submit customers 
     Patch(Customers,
     ForAll(colCustomers, 
     {
     Name: Name,
     TicketRequestId: varLastSubmitID
     }
     )
     );

    The CountRows is a waste of time as if it is empty (zero) then the Patch will do nothing anyway.

    The Defaults is a waste as Patch observes the ID of the record you provide.  If there is none, it will create a record.

    The only reason you need Defaults is if you have defined default values in your list.  

    IF you have a real need for Defaults, then it would be incorporated into your formula as:

     // now submit customers 
     Patch(Customers,
     ForAll(colCustomers, 
     Patch(Defaults(Customers), 
     {
     Name: Name,
     TicketRequestId: varLastSubmitID
     }
     )
     )
     );

     

    Overall, I would recommend using the Gallery instead of a collection.  The gallery will already contain all the data you need and this will keep you from wasting time on writing formulas in OnChange actions and such to update a collection.  All of that is just extra work.

    If you have a specific need for it, then by all means.  But otherwise, keep it super simple and PowerApps will be your friend.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 477

#2
WarrenBelz Profile Picture

WarrenBelz 341 Most Valuable Professional

#3
11manish Profile Picture

11manish 317

Last 30 days Overall leaderboard