cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

In Javascript, access parent entity record when adding new child record

In our model-driven app, I have a 1:N relationship between 2 entities.  On the form to add related child records, I want to use javascript on the onChange event of a lookup field to populate another field on the form.  To get the data for the other field, I need to access the parent entity record and get data from it and other entities related to it.  Can anyone provide an example of how to access the parent and other related entities in javascript when child record hasn't been saved yet?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Hi @tschopp , 

 

If it's a child entity, then you have a lookup to the parent record. This lookup is usually filled in on the form, even when the child record is not saved. When the form is opened, the platform will pass this parameters (and in case you open the form using code, you can do that too).

So even in "Create Mode" you can grab the id of the parent, and can make fetches for related records.

Please let me know, in case you need more details.

 

Kind regards,

Diana

View solution in original post

2 REPLIES 2
Super User
Super User

Hi @tschopp , 

 

If it's a child entity, then you have a lookup to the parent record. This lookup is usually filled in on the form, even when the child record is not saved. When the form is opened, the platform will pass this parameters (and in case you open the form using code, you can do that too).

So even in "Create Mode" you can grab the id of the parent, and can make fetches for related records.

Please let me know, in case you need more details.

 

Kind regards,

Diana

View solution in original post

Thanks @DianaBirkelbach .  I see now that if I add a lookup control for the parent on the form, it is populated in Create Mode and I can access it's value from the formContext in JS.

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Users online (3,897)