Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

addCustomView misbehaves

Posted on by 1,010
    this.addMQtoPriceListItemFilter = function (ExecutionContext, dfltPxLstId, MQpxLstId) {
        formContext = ExecutionContext.getFormContext();
        Products_in_Parent_Price_List_savedqueryid = "BCC509EE-1444-4A95-AED2-128EFD85FFD5";
        Products_in_both_Price_Lists_savedqueryid = "990143DD-7576-E911-A96A-000D3A4E75C3"; //dummied
        fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>"
            + "<entity name='product'>"
            +   "<attribute name='name' />"
            +   "<attribute name='price' />"
            +   "<attribute name='defaultuomid' />"
            +   "<attribute name='productnumber' />"
            +   "<attribute name='productid' />"
            +   "<order attribute='productnumber' descending='false' />"
            +   "<filter type='and'>"
            +     "<filter type='or'>"
            +       "<condition attribute='statecode' operator='eq' value='0' />"
            +       "<condition attribute='statecode' operator='eq' value='3' />"
            +     "</filter>"
            +   "</filter>"
            +   "<link-entity name='productpricelevel' from='productid' to='productid' link-type='inner' alias='aa'>"
            +     "<filter type='and'>"
            +       "<condition attribute='pricelevelid' operator='in'>"
            +         "<value uitype='pricelevel'>{" + dfltPxLstId + "}</value>"
            +         "<value uitype='pricelevel'>{" + MQpxLstId + "}</value>"
            +       "</condition>"
            +     "</filter>"
            +   "</link-entity>"
            + "</entity></fetch>";
        Xrm.WebApi.retrieveRecord("savedquery", Products_in_Parent_Price_List_savedqueryid, "?$select=layoutxml").then(
            function success(result) { 
                if (result.layoutxml)
                    formContext.getControl("productid").addCustomView(Products_in_both_Price_Lists_savedqueryid,
                        "product", "Products in both Price Lists", fetchXML, result.layoutxml, true)
            },
            function (error) {
                formContext.ui.setFormNotification("Product view: " + error.message, "ERROR", "_Products_in_Parent_Price_List");
            }
        );
    };

-------------------------------------------

This is loaded against an opportunityProduct quick create form on the Existing Product (productid) field:

  1. the view does not become default; defaults to top of the list
  2. in the selector it shows as a personal view
  3. when chosen it doesn't list the correct items (I've tested the fetch in both Advanced find and FetchTester)

Any ideas why?

thanks,

*This post is locked for comments

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,010 on at
    RE: addCustomView misbehaves

    Thanks, Radu, et al for waiting.

    I tried your suggestion -- it doesn't change the behavior.  New script:

        this.addMQtoPriceListItemFilter = function (ExecutionContext, dfltPxLstId, MQpxLstId) {
            formContext = ExecutionContext.getFormContext();
            Products_in_Parent_Price_List_savedqueryid = "BCC509EE-1444-4A95-AED2-128EFD85FFD5";
            Products_in_both_Price_Lists_savedqueryid = "990143DD-7576-E911-A96A-000D3A4E75C3"; //dummied
            fetchXML = "<?xml version='1.0'?>"
                + "<fetch version='1.0' mapping='logical'>"
                + "<entity name='product'>"
                +   "<attribute name='name' />"
                +   "<attribute name='price' />"
                +   "<attribute name='defaultuomid' />"
                +   "<attribute name='productnumber' />"
                +   "<attribute name='productid' />"
                +   "<order attribute='productnumber' descending='false' />"
                +   "<filter type='and'>"
                +     "<filter type='or'>"
                +       "<condition attribute='statecode' operator='eq' value='0' />"
                +       "<condition attribute='statecode' operator='eq' value='3' />"
                +     "</filter>"
                +   "</filter>"
                +   "<link-entity name='productpricelevel' from='productid' to='productid' link-type='inner' alias='aa'>"
                +     "<filter type='and'>"
                +       "<condition attribute='pricelevelid' operator='in'>"
                +         "<value uitype='pricelevel'>{" + dfltPxLstId + "}</value>"
                +         "<value uitype='pricelevel'>{" + MQpxLstId + "}</value>"
                +       "</condition>"
                +     "</filter>"
                +   "</link-entity>"
                + "</entity></fetch>";
            layoutxml = "<?xml version='1.0'?>"
                + "<grid icon='1' preview='0' select='1' jump='name' object='1024' name='resultset'>"
                +   "<row name='result' id='productid'>"
                +     "<cell name='name' width='200'/>"
                +     "<cell name='price' width='100'/>"
                +     "<cell name='defaultuomid' width='100'/>"
                +     "<cell name='productnumber' width='100'/>"
                +   "</row>"
                + "</grid>";
    
            formContext.getControl("productid").addCustomView(Products_in_both_Price_Lists_savedqueryid,
                            "product", "Products in both Price Lists", fetchXML, layoutxml, true)
        };
    


    Again, not default view:

    goesCustom.PNG

  • Suggested answer
    Radu Chiribelea Profile Picture
    Radu Chiribelea 6,667 on at
    RE: addCustomView misbehaves

    I see you are fetching the layoutXml from the platform  Xrm.WebApi.retrieveRecord("savedquery", Products_in_Parent_Price_List_savedqueryid, "?$select=layoutxml")

    If you try hardcoding that in your code, instead of querying the crm platform, does it make any difference?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans