Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Adding two custom views using addCustomView

(0) ShareShare
ReportReport
Posted on by 40

Hello,

Does anyone know if it is possible to add two customer views to a lookup field using the addCustomView call?

Thank you

  • CU13060040-0 Profile Picture
    on at
    Adding two custom views using addCustomView
    Hey guys I am using a different ViewId however it only still shows me the second one or the one I set true as the default view. Please help.
     
     
    viewIdInsured = '{00000000-0000-0000-0000-000000000001}';
    viewIdOwner = '{00000000-0000-0000-0000-000000000012}';

    var fetchXmlInsured =
    '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">' +
    '<entity name="account">' +
    '<attribute name="name"/>' +
    '<attribute name="accountid"/>' +
    '<order attribute="name" descending="false"/>' +
    '<link-entity name="ice_product_lifeinsuredaccount" from="accountid" to="accountid" visible="false" intersect="true">' +
    '<link-entity name="ice_product" from="ice_productid" to="ice_productid" alias="ae">' +
    '<filter type="and">' +
    '<condition attribute="ice_productid" operator="eq" uiname="" uitype="ice_product" value="' + productIdValue + '"/>' +
    '</filter>' +
    '</link-entity>' +
    '</link-entity>' +
    '</entity>' +
    '</fetch>';

    var fetchXmlOwner = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">' +
    '<entity name="account">' +
    '<attribute name="name"/>' +
    '<attribute name="accountid"/>' +
    '<order attribute="name" descending="false"/>' +
    '<link-entity name="ice_account_ice_product" from="accountid" to="accountid" visible="false" intersect="true">' +
    '<link-entity name="ice_product" from="ice_productid" to="ice_productid" alias="ab">' +
    '<filter type="and">' +
    '<condition attribute="ice_productid" operator="eq" uiname="" uitype="ice_product" value="' + productIdValue + '"/>' +
    '</filter>' +
    '</link-entity>' +
    '</link-entity>' +
    '</entity>' +
    '</fetch>';

    var layoutXml = "<grid name= ' resultset' object=' 10039' jump= ' name ' <row name=' result' id=' accountid'> <cell name= 'name' width=' 200' / > < / row> </grid>";
    debugger;

    let layoutXMLCustomerInsured = createLayoutXML();
    let layoutXMLCustomerOwner = createLayoutXML();

    formContext.getControl("ice_customer").addCustomView(viewIdInsured, "account", "Customer Insured", fetchXmlInsured, layoutXml, true);
    formContext.getControl("ice_customer").addCustomView(viewIdOwner, "account", "Customer Owner", fetchXmlOwner, layoutXml, false);
  • Piyush Parihar Profile Picture
    on at
    RE: Adding two custom views using addCustomView

    Hi Andrew,

    I am trying with the same scenario,But for me I have 2 different entities that are bind to lookup on which we are adding customview.I am getting only results from first addCustomView not from second addCustomView.Any pointers that can help?

    Thanks in advance.

  • Tuddrussel Profile Picture
    40 on at
    RE: Adding two custom views using addCustomView

    That did the trick! You sir are a genius!

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Adding two custom views using addCustomView

    You use the same guid for the view:

    AddView.png

    Fix it and you should be good. Good luck.

  • Tuddrussel Profile Picture
    40 on at
    RE: Adding two custom views using addCustomView

    Thanks Andrew!

    I think I'm using different GUIDs (or at least fetching everything correctly) but when I look at the field after publishing I only see the later of the two views (Invoices by Billing Account).  My code is below (it needs to be cleaned up a bit but hopefully it gets everything correctly).

    /*
    function addCustomInvoiceView(executionContext)
    input - executionContext
    output - N/A
    description - takes the value entered in the RMA field, Service Account and Billing Account fields to create two customer views
    */
    function addCustomInvoiceView(executionContext)
    {
        let formContext = executionContext.getFormContext();    // get form context
    
        if ( !formContext.getAttribute('po_rma').getValue()[0].name
            || !formContext.getAttribute('po_serviceaccountid').getValue()[0].name
            || !formContext.getAttribute('po_billingaccountid').getValue()[0].name )
        {
            console.log("One of the following values were not found: RMA #, Service Account and Billing Account");
        }
        else
        {
            let viewID = '{00000000-0000-0000-0000-000000000001}';  // dummy GUID
            let entityName = 'invoicedetail'; 
            let invoicesServiceAccountName = "Invoices By Service Account";
            let invoicesBillingAccountName = "Invoices by Billing Account";
    
            let rmaProductNumber = formContext.getAttribute('po_rmaproduct').getValue()[0].name;
            let rmaProductGUID = formContext.getAttribute('po_rmaproduct').getValue()[0].id;
            let serviceAccountName = formContext.getAttribute('po_serviceaccountid').getValue()[0].name;
            let serviceAccountGUID = formContext.getAttribute('po_serviceaccountid').getValue()[0].id;
            let billingAccountName = formContext.getAttribute('po_billingaccountid').getValue()[0].name;
            let billingAccountGUID = formContext.getAttribute('po_billingaccountid').getValue()[0].id;
    
            Xrm.WebApi.online.retrieveRecord("msdyn_rmaproduct", rmaProductGUID, "?$select=_msdyn_product_value").then(
                function success(result) {
                    let _msdyn_product_value = result["_msdyn_product_value"];
                    let _msdyn_product_value_formatted = result["_msdyn_product_value@OData.Community.Display.V1.FormattedValue"];
                    let _msdyn_product_value_lookuplogicalname = result["_msdyn_product_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
    
                    let productGUID = "{"   result._msdyn_product_value   "}";
                    let fetchXMLServiceAccount = createFetchXML(rmaProductNumber, productGUID, serviceAccountName, serviceAccountGUID);
                    let layoutXMLServiceAccount = createLayoutXML();
                    let fetchXMLBillingAccount = createFetchXML(rmaProductNumber, productGUID, billingAccountName, billingAccountGUID);
                    let layoutXMLBillingAccount = createLayoutXML();
                    formContext.getControl('po_custominvoicelinefilterid').addCustomView(
                        viewID, entityName, invoicesServiceAccountName, fetchXMLServiceAccount, layoutXMLServiceAccount, true);
                    formContext.getControl('po_custominvoicelinefilterid').addCustomView(
                        viewID, entityName, invoicesBillingAccountName, fetchXMLBillingAccount, layoutXMLBillingAccount, false);
                },
                function(error) {
                    //Xrm.Utility.alertDialog(error.message);           // default error.message
                    console.log(`addCustomInvoiceView/Xrm.WebApi.online.retrieveRecord/error.message: ${error.message}`);
                }
            );
        }
    }
    
    function createFetchXML(productNumber, productGUID, accountName, accountGUID)
    {  
        let fetchXML = 
            ""
             ""
                 ""
                 ""
                 ""
                 ""
                 ""
                     ""
                     ""
                 ""
                 ""
                     ""
                     ""
                         ""
                     ""
                 ""
             ""
             "";
    
        return fetchXML;
    }
    
    function createLayoutXML()
    {
        let layoutXML = 
            ""
             ""
                 ""
                 ""
                 ""
             ""
             "";
    
        return layoutXML;
    }

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Adding two custom views using addCustomView

    Hello,

    That sounds absolutely doable. The main point - use different Guids for views when you add.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans