cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MWierckx
Advocate I
Advocate I

LookUp function CDS same name fields (different entities)

Dear all,

 

I've been working on a product configurator app for my company based on data that we use in our Dynamics 365 CRM environment. I've come a long way using connections to Dynamics Data sources. Today I tried to experiment a bit with making connections to the same entities via CDS.

 

Currently I'm facing an issue that I don't have problems with when using Dynamics data sources, however I would like to understand how to do it with CDS connections.

 

I have an entity Products with the field Product (containing the GUID of the record) and I have an entity Projectitem with a LookUp field named Product (in which I can select a Product record). I'm creating a collection in the app in which I'm searching for the product name in the Products entity based on a selection of Projectitem records. For the name I'm using a LookUp:

 

ForAll(
          Projectitems;
          Collect(
                Selected_Product_Table;
                {
                         Productname: LookUp(
                         Products;
                         Product = Product; Name
                         )
                }
           )
)

I've tried to specify both Product fields by referring to the entity in the formula, meaning: Products[@Product] = Projectitems[@Product]. I also tried using the unique environment names, but no luck. Basically I've tried all combinations of reference, display names and environment names... no luck.

 

In the app that I've based on the Dynamics data sources, this LookUp works with specifying the unique environment names.

 

Can anybody point out what I'm doing wrong and how to build up the correct reference to get the name of the product selected with a LookUp field on a different entity?

 

Appreciating any feedback!

 

Best regards,

 

M.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Dear @yashag2255 ,

 

Thank you for your reply!

 

Unfortunately this isn't the solution, however it did help me find the right one - thinking about your comment on not having to use the LookUp function.

 

For filling the variable 'Productname' in a new collection I now do the following:

 

ForAll(
        Projectitems;
                      Collect(
                              Selected_Products_Table;
                              {
                              Productname: Product.Name
                              }
                       )
)

Because I'm doing this for the Projectitems entity (in the ForAll Function) when I refer to Product (in the Product.Name part) it's referring to the Product LookUp field on the Projectitem record. Then by adding the .Name it's using the name field of the Product record.

 

Again thanks for giving me the insight!

 

Best regards,

 

M.

View solution in original post

3 REPLIES 3
yashag2255
Dual Super User II
Dual Super User II

Hi @MWierckx 

 

To collect the names of all the Products from the lookup field, you do not need to perform a LookUp operation, this can directly be fetched from the entity. In dynamics the attribute that contains the record differs a bit. Can you try out the below expression:
 
ClearCollect(Selected_Product_Table, Projectitems.'Product (cbisa_Product)'.Name)
 
You need to replace the highlighted part with the actual attribute name, this need to be similar to 'LookUpFieldName (prefix_LookUpFieldName)', one with the logical name.

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Dear @yashag2255 ,

 

Thank you for your reply!

 

Unfortunately this isn't the solution, however it did help me find the right one - thinking about your comment on not having to use the LookUp function.

 

For filling the variable 'Productname' in a new collection I now do the following:

 

ForAll(
        Projectitems;
                      Collect(
                              Selected_Products_Table;
                              {
                              Productname: Product.Name
                              }
                       )
)

Because I'm doing this for the Projectitems entity (in the ForAll Function) when I refer to Product (in the Product.Name part) it's referring to the Product LookUp field on the Projectitem record. Then by adding the .Name it's using the name field of the Product record.

 

Again thanks for giving me the insight!

 

Best regards,

 

M.

View solution in original post

Hi @yashag2255 @MWierckx 

 

Thanks for your posts and @MWierckx  thanks for your solution.

This will be useful for others.

 

Best Regards.

Yumia

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Kudoed Authors
Users online (20,129)