cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TimRohr
Level 10

How to get info of related entity?

I have 3 entities (Regions {1:N} RegionalGroups {1:N} Roles).

 

RegionalGroups has a lookup field relating to Regions. Roles has a lookup field relating to RegionalGroups.

 

If I show the RegionalGroups in a Gallery, I can pull in the name of the associated Region using:

ThisItem.Region.RegionName

 

However, if I show the Roles in a Gallery, how do I get the Region info (a step removed)?

 

I can get the RegionalGroup from the Role itself:

ThisItem.RegionalGroup.RegionalGroup

 

But if I put that into a LookUp() function top try to get the Region or the RegionName, I get a blank return:

LookUp(RegionalGroups, RegionalGroup = ThisItem.RegionalGroup.RegionalGroup, Region.RegionName)

 

"Region" is a lookup field on the RegionalGroups entity, and RegionName is a field in the Regions entities.

 

How do we get information from an entity 2-relationships removed?

 

1 ACCEPTED SOLUTION

Accepted Solutions
TimRohr
Level 10

Re: How to get info of related entity?

OK, after working with a Microsoft tech, I found out there is nothing wrong with my LookUp() formula. It SHOULD work. However, I also learned that LookUp() doesn't always return the data, even if the data is there to be found. If it can't return the data (or thinks it has found nothing), it returns blank... which is what I was seeing.


Changing my LookUp() statements to be First(Filter()) statements worked. So, as an example, if my statement used to be:

Lookup(RegionalGroups,RegionalGroup=GroupID,Region.Region)

We changed it to:

First(Filter(RegionalGroups,RegionalGroup=GroupID)).Region.Region

And that pulled it in.

View solution in original post

3 REPLIES 3
PauwelsSven
Level 8

Re: How to get info of related entity?

Hi,

 

LookUp(RegionalGroups, RegionalGroup = ThisItem.RegionalGroup.RegionalGroup, Region.RegionName)

Region won't work because you Lookup RegionalGroups.

First do a lookup to regionalgroups -> Regionalgroups.Region, then Region -> regionalsgroups.region, Region.RegionName.

 

Regards.

Highlighted
TimRohr
Level 10

Re: How to get info of related entity?

 

Hi, @PauwelsSven...

 

Help me understand what you mean, because I've tried to pull the pieces in as you suggest, without success. For instance, to get to the Role screen, I am either coming from the RegionalGroups screen (which has a Gallery of associated Roles), or I am coming from the Employee screen (which has a Gallery of associated Roles). Either way, I Navigate() to the Role screen and set a Context Variable of "GroupID" to be the RegionalGroup, and a Context Variable of "RoleID" to be the Role I want to see. That lets me use the same destination screen (the Role screen) to display the Role... (I can't set the Item of the Form to be RolesForGroups_BrowseGallery.Selected, since I might be coming from the Employee screen, where the Gallery is called RolesForEmployee_BrowseGallery; instead I set the Item to be a First() of a Filter() where the Role equals my RoleID).

 

First(Filter('HR Group Roles','HR Group Role'=RoleID))

 

So, having the GroupID, I try to get the Region through a LookUp():

 

UpdateContext({RegionID:LookUp(RegionalGroups,RegionalGroup=GroupID,Region.Region)})

If I can get the RegionID, I can get the RegionName through its own LookUp(). I think that's what you mean. However...

 

I have put that UpdateContext statement in the OnVisible of my Role screen, and set a Label to have a Text property of RegionID. It is blank.

 

I have also tried to use the formula, above, on the OnSelect property of the Gallery that Navigates to the Role screen. In other words, when you pick the Role from the Gallery (whether on the Employee or the RegionalGroup screen), I set the RegionID on *that* form. Then I pass the RegionID context variable from the calling screen to the Role screen in the Navigate() function:

 

Navigate(Role_DetailScreen,ScreenTransition.None,{EmployeeID: EmployeeID,
GroupID: GroupID,
RegionID: RegionID,
RoleID: RolesForEmployee_BrowseGallery.Selected.'HR Group Role'})

I test the RegionID variable in the OnVisible event of the Role screen, and it is blank.

 

The more I look at this, the more I wonder if it is a corruption of the data, somehow. Is that possible? When I go to the RegionalGroup entity in CDS, view the data, and choose the "All Fields" view, the fields are completely blank... until I have clicked on the record (sometimes multiple times). However, multiple records seem to be selected automatically when I first open the view, and though I click from one record to another without holding a key down on the keyboard, sometimes it adds to the selected records (leaving others selected), sometimes it clears the other records that are selected. Along the way, the fields that were blank become populated. I've attached a video of the behavior... nowhere in the video am I holding SHIFT or any other key.

TimRohr
Level 10

Re: How to get info of related entity?

OK, after working with a Microsoft tech, I found out there is nothing wrong with my LookUp() formula. It SHOULD work. However, I also learned that LookUp() doesn't always return the data, even if the data is there to be found. If it can't return the data (or thinks it has found nothing), it returns blank... which is what I was seeing.


Changing my LookUp() statements to be First(Filter()) statements worked. So, as an example, if my statement used to be:

Lookup(RegionalGroups,RegionalGroup=GroupID,Region.Region)

We changed it to:

First(Filter(RegionalGroups,RegionalGroup=GroupID)).Region.Region

And that pulled it in.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,049)