web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

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

  • Tuddrussel Profile Picture
    40 on at

    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;
    }

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

    That did the trick! You sir are a genius!

  • Piyush Parihar Profile Picture
    on at

    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.

  • CU13060040-0 Profile Picture
    on at
    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);

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans