SBX - Search With Button

SBX - Forum Post Title

addCustomView misbehaves

Microsoft Dynamics CRM Forum

mardukes asked a question on 15 May 2019 9:19 AM
My Badges

Question Status

Suggested Answer
    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,

Reply
Radu Chiribelea responded on 15 May 2019 2:25 PM
My Badges
Suggested Answer

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?

Reply
Radu Chiribelea responded on 15 May 2019 2:25 PM
My Badges
Suggested Answer

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?

Reply

SBX - Two Col Forum

SBX - Migrated JS