Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Adding two custom views using addCustomView

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
    CU13060040-0 5 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);
  • 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
    Tuddrussel 40 on at
    RE: Adding two custom views using addCustomView

    That did the trick! You sir are a genius!

  • Verified answer
    a33ik Profile Picture
    a33ik 84,313 Super User 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
    Tuddrussel 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
    a33ik 84,313 Super User 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans