Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

CRM Embedded Canvas App Gallery Filter

  • 1.  CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 23 days ago
    Edited by Andy Arndt 23 days ago
    I'm working on two Canvas apps to use as controls on a CRM form. The form is for a custom entity and I want to display related customeraddress records. Because you can't have a lookup field to customeraddress, I use an integer field on the custom entity that has a corresponding integer value on a customeraddress record.

    I created the two apps from the form design in CRM so that they have the context of the form and the ModelDrivenFormIntegration object is available to me.

    One Canvas app has a gallery that has a filter condition where it compares a custom field on the customeraddress entity (Addresses in the PowerApp designer) to a field on the form. This works with a formula like this: Filter(Addresses, fieldname = ModelDrivenFormIntegration.Item.'fieldname')

    I have that published and it's working fine on the CRM form and displays the one customeraddress record I would expect.

    The second Canvas app has a gallery that has a filter condition where it filters based on the Parent field on the customeraddress entity equal to a Contact lookup field on the form. The formula looks like this: Filter(Addresses, 'Parent' = ModelDrivenFormIntegration.Item.'contactlookupfieldname')

    Intellisense presented the field names for me to select in the formula so I know that it was recognizing valid field names. The formula checker says that everything is fine, but there are no results when rendering the form in CRM. I see a blank area where the Canvas app screen should be, but there should be 7 related addresses displaying. Some things I've tried:

    1. Tried to Play the app in the PowerApp designer but it doesn't have the context of the form so that's not a good test
    2. Tried to add a test in the Advanced Tools area, but didn't get very far with that
    3. Tried doing an f12 debug on the CRM form to see what was happening on the Console and Network tabs but couldn't find useful info specifically for the Canvas app control

    Any ideas of a good way to troubleshoot this?

    Thanks.

    #CustomerEngagement​​ #PowerApps

    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------
    Academy - Online Interactive Learning from Experts


  • 2.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 22 days ago

    Hey Andy I found an interesting article that might help:

    https://dynamicsninja.blog/2018/12/26/embedded-canvas-apps-dynamic-d365-context/

    In his example he calls a function to actually get the GUID of the record you want to reference and then later references it when he goes to filter the gallery.

    Not sure if this is exactly what needs to happen but might be worth a shot.

    Thanks!



    ------------------------------
    Doug Apicella
    Solution Architect
    Hitachi Solutions
    SC
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 3.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 22 days ago
    Doug,

    Thanks for the link. I'll see if this solves what I'm trying to do. So far I've been able to do everything I want with hard-coded values in some places. There are two pieces left that I need to get working dynamically without needing the hard coded values. I'll reply back here with more information if I can get it to work.

    Thanks,
    Andy

    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 4.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 21 days ago
    I'm really stumped on filtering an address Gallery control by the Parent. The formula looks like this:

    Filter(Addresses, 'Parent' = ModelDrivenFormIntegration.Item.'contactlookupfieldname')

    I was focused on the right side of the condition but I now think the 'Parent' field is the problem. The formula checker says invalid argument and I think at one point during troubleshooting I saw a message "this data type cannot be used for comparison".  Maybe it's because Parent on customeraddress is a polymorphic Lookup field. I've been reading about how to handle those in formulas, but still no luck.

    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 5.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 21 days ago
    Might be getting close with this. It passes the formula checker, but still no results in the Gallery at runtime on the form. This is the formula in the Items property of the Gallery.

    Filter(Addresses, If(IsType('Parent', [@Contacts] ),
    AsType('Parent', [@Contacts]).Contact,
    AsType('Parent', [@Accounts]).Account) = ModelDrivenFormIntegration.Item.'contactlookupfieldname'.Contact)

    The lookup field on the form will always be a contact, but the If condition needed an else.

    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 6.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 21 days ago
    Andy I found this article that might help. https://eelane.com/2019/08/25/embedded-canvas-app-pt2-create-gallery-n-polymorphic-lookup/

    It looks like the author isn't defining both entities for the lookup:



    ------------------------------
    Doug Apicella
    Solution Architect
    Hitachi Solutions
    SC
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 7.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 20 days ago
    Thanks for the additional idea Doug. I tried just the one condition in the if and this still didn't work for me. I posted a question in the PowerApps community forum and I'm hoping someone has run into this specific problem before and has solved it. When I think about it, the requirement is fairly simple: I want to display addresses for a particular contact.

    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 8.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 9 days ago

    Here's an update on this. The Parent property of the customeraddress entity is not the problem with the Gallery filter. I have it working when I hard-code a GUID for a Contact like this example:

     

    Filter(Addresses, If(IsType(Addresses[@'Parent'], [@Contacts] ),

    AsType(Addresses[@'Parent'], [@Contacts]).contactid

     = GUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")))

     

    The problem is when I try to retrieve the Contact GUID from a Contact lookup field on the Dynamics CE form where the Canvas App is embedded. 

     

    Filter(Addresses, If(IsType(Addresses[@'Parent'], [@Contacts] ),

    AsType(Addresses[@'Parent'], [@Contacts]).contactid

     = ModelDrivenFormIntegration.Item.'contactlookupfieldname'.contactid))

     

    I've tried many variations including trying to place the Contact GUID in a global variable and then using the variable in the Filter. I found a post that appears to describe the same problem, but I can't get the proposed solution to work. The title of the post is "Embedded canvas app ModelDrivenFormIntegration.Item.[Lookupfield] always returns emtpy".  https://powerusers.microsoft.com/t5/Common-Data-Service-for-Apps/Embedded-canvas-app-ModelDrivenFormIntegration-Item-Lookupfield/m-p/333802#M2180



    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------

    Academy - Online Interactive Learning from Experts


  • 9.  RE: CRM Embedded Canvas App Gallery Filter

    GOLD CONTRIBUTOR
    Posted 9 days ago
    I solved it. I needed to retrieve the full record for the entity on the form and then retrieve the GUID of the lookup field from there.

    I set a variable like this:

    Set(varname,LookUp('form entity name', formentityprimaryidentifiername = ModelDrivenFormIntegration.Item.formentityprimaryidentifiername).contactlookupfield.contactid);

    Then I use the variable in the Filter like this:

     Filter(Addresses, If(IsType(Addresses[@'Parent'], [@Contacts] ), AsType(Addresses[@'Parent'], [@Contacts]).contactid = varname))


    I found the answer on this post: https://medium.com/hitachisolutions-braintrust/overcoming-top-5-challenges-with-embedded-canvas-apps-f5698b32a7b5

    The relevant piece was:

    1. Challenge #1: The ModelDrivenFormIntegration control does not fetch values for fields of related entities. For example, the following will not work to get the list of contacts for an account (when the control is connected to the accounts entity):

    ModelDrivenFormIntegration.Item.Contacts

     

    Trick #1: The ModelDrivenFormIntegration control should only be used to obtain the GUID of the contextual record. The CDS connector, along with Lookup, should be used to obtain the complete record.



    ------------------------------
    Andy Arndt
    Minitab, Inc.
    State College PA
    ------------------------------

    Academy - Online Interactive Learning from Experts


If you've found this thread useful, dive deeper into User Group community content by role