cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LinnZawWin
Kudo Kingpin
Kudo Kingpin

How to Collect lookup GUID value from CDS lookup Field or Join two CDS Data Sources

How to join two CDS data source via lookup GUID value to get the GUID value of the lookup value of parent record? (in short, grandparent record GUID)


E.g. I have 3 entities.
1. Assessment Section
2. Assessment Question
3. Assessment Details

Assessment Details has a lookup field for entity Assessment Question.
Assessment Question has a lookup field for entity Assessment Section.

What I want is the GUID value for "Assessment Section" lookup field on "Assessment Question" entity to be added to the collection together with "Assessment Details" data

 

I tried to AddColumn using the following formula but

  • zzlocalassessmentsectionid (getting a lookup value of lookup record returns an empty data even though "zzTextField" returns the data though since it is a text field)
  • zzlookupassessmentsectionid (lookup to the Assessment Question returns value for the other text fields but not the lookup field. If I set the same Lookup function to a label text value with hardcoded "Assessment Question" GUID, it is working fine)

*Screenshot attached*

 

 

ClearCollect(colTest,
    AddColumns
    (
        'Assessment Details',
        "zzTextField",
        assessmentquestionid.'Question Text',
        "zzlocalassessmentsectionid",
        assessmentquestionid.'Assessment Section',
        "zzlookupassessmentsectionid",
        LookUp
        (
            'Assessment Questions', 
            'Assessment Question' = assessmentquestionid.'Assessment Question', 
            'Assessment Section'.'Assessment Section'
        )
    )
)

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi  @LinnZawWin ,

 

What is the assessmentquestionid? the lookup field of 'Assessment Details'?

I'm sure this is not a easy way, but it works on my test. We can't get the Lookup value of lookup field in batches, so we have to first get the GUID field Name of Assessment Question, then patch the GUID2(the Assessment Section lookupfield of  Assessment Questions ) to collection. Please try the following formula, If this doesn't work, please post back more details information.

Note: I assume that GUID field Name of three entity is the same with entity name.

 

ClearCollect(colTest,
    AddColumns
    (
        'Assessment Details',
        "zzTextField",
        assessmentquestionid.'Question Text',
        "GUID1"
        assessmentquestionid.'Assessment Question', /*Get GUID field Name of Assessment Question lookup field*/
        "GUID2",
        ""
    )
);
ClearCollect(coltest3,colTest);
ClearCollect(coltest4,'Assessment Question');
ForAll(
    coltest4,
    ForAll(
        coltest3,
        If(
            'Assessment Question' = GUID1,
            Patch(
                colTest,
                LookUp(
                    colTest,
                    'Assessment Details' = coltest3[@'Assessment Details']
                ),
                {
                    GUID2: LookUp(
                        'Assessment Question',
                        'Assessment Question' = coltest4[@'Assessment Question'],
                        'Assessment Section'.'Assessment Section' /* LookUpfied.GUID */
                    )
                }
            )
        )
    )
)

 

Snipaste_2019-11-12_14-31-40.png

Best regards,

Sik

If my post is helpful for you, please click on “Accept as Solution” to help other members find it more quickly.

View solution in original post

@v-siky-msft Thanks for your response. It's a shame that we can't get the Lookup value of the lookup field (not even GUID).

Your sample code is also useful for me. It inspired me to come up with the idea to patch the collection instead.

And here is the modified version to update all the rows of the collection and populate the Lookup GUID value of the parent record.

UpdateIf(
    colTest, 
    true, 
    {
        assessmentsectionid: LookUp
        (
            'Assessment Questions', 
            'Assessment Question' = dxc_assessmentquestionid,
            'Assessment Section'.'Assessment Section'
        )
    }
);

 

View solution in original post

2 REPLIES 2
v-siky-msft
Community Support
Community Support

Hi  @LinnZawWin ,

 

What is the assessmentquestionid? the lookup field of 'Assessment Details'?

I'm sure this is not a easy way, but it works on my test. We can't get the Lookup value of lookup field in batches, so we have to first get the GUID field Name of Assessment Question, then patch the GUID2(the Assessment Section lookupfield of  Assessment Questions ) to collection. Please try the following formula, If this doesn't work, please post back more details information.

Note: I assume that GUID field Name of three entity is the same with entity name.

 

ClearCollect(colTest,
    AddColumns
    (
        'Assessment Details',
        "zzTextField",
        assessmentquestionid.'Question Text',
        "GUID1"
        assessmentquestionid.'Assessment Question', /*Get GUID field Name of Assessment Question lookup field*/
        "GUID2",
        ""
    )
);
ClearCollect(coltest3,colTest);
ClearCollect(coltest4,'Assessment Question');
ForAll(
    coltest4,
    ForAll(
        coltest3,
        If(
            'Assessment Question' = GUID1,
            Patch(
                colTest,
                LookUp(
                    colTest,
                    'Assessment Details' = coltest3[@'Assessment Details']
                ),
                {
                    GUID2: LookUp(
                        'Assessment Question',
                        'Assessment Question' = coltest4[@'Assessment Question'],
                        'Assessment Section'.'Assessment Section' /* LookUpfied.GUID */
                    )
                }
            )
        )
    )
)

 

Snipaste_2019-11-12_14-31-40.png

Best regards,

Sik

If my post is helpful for you, please click on “Accept as Solution” to help other members find it more quickly.

View solution in original post

@v-siky-msft Thanks for your response. It's a shame that we can't get the Lookup value of the lookup field (not even GUID).

Your sample code is also useful for me. It inspired me to come up with the idea to patch the collection instead.

And here is the modified version to update all the rows of the collection and populate the Lookup GUID value of the parent record.

UpdateIf(
    colTest, 
    true, 
    {
        assessmentsectionid: LookUp
        (
            'Assessment Questions', 
            'Assessment Question' = dxc_assessmentquestionid,
            'Assessment Section'.'Assessment Section'
        )
    }
);

 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,656)