简体   繁体   中英

Cannot read property 'SetParameter' of undefined in Dynamics CRM while setting up fetchXML of a subgrid

I've following code snippet to set up the fetchxml of a subgrid on invoice form but it throws the exception: Cannot read property 'SetParameter' of undefined .

Any Idea how it could be resolved.

Code Snippet:

function filterUsers() {
    try {
        debugger;
        var orderId = Xrm.Page.getAttribute("salesorderid").getValue()[0].id;
        var spGrid = getSubgrid("new_salesperson");
        //var spGrid = Xrm.Page.getControl("new_salesperson");
        if (spGrid == null || spGrid == 'undefined') {
            setTimeout(filterUsers, 500);
            return;
        }
        else {
            var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                    "  <entity name='systemuser'>" +
                    "    <attribute name='fullname' />" +
                    "    <attribute name='title' />" +
                    "    <attribute name='address1_telephone1' />" +
                    "    <attribute name='systemuserid' />" +
                    "    <order attribute='fullname' descending='false' />" +
                    "    <link-entity name='new_salesorder_systemuser' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" +
                    "      <link-entity name='salesorder' from='salesorderid' to='salesorderid' alias='ab'>" +
                    "        <filter type='and'>" +
                    "          <condition attribute='salesorder' operator='eq' value='" + orderId + "' />" +
                    "        </filter>" +
                    "      </link-entity>" +
                    "    </link-entity>" +
                    "  </entity>" +
                    "</fetch>";
            spGrid.control.SetParameter("fetchXml", fetchXml);
            spGrid.control.SetParameter("effectiveFetchXml", fetchXml);
            spGrid.control.SetParameter("fetchXmlForFilters", fetchXml);
            spGrid.control.refresh();
        }
    }
    catch (e) {
        if (e.message == "Cannot read property '0' of null" || e.message == "orders[0] is undefined" || e.message == "Unable to get property '0' of undefined or null reference")
            return;
        alert("Error: " + e.message);
    }

}

function getSubgrid(elementName) {
    debugger;
    if (document.getElementById(elementName) == null || document.getElementById(elementName) == 'undefined') {
        return window.parent.document.getElementById(elementName);
    }
    else {
        return document.getElementById(elementName);
    }
}

Manipulating the DOM directly in CRM is not supported. Find another way.

It appears to me that you are trying to add a subgrid of users to the invoice form. The users have been associated with sales orders with your custom relation, new_salesorder_systemuser .

I would suggest simply creating a quick view form on sales order with the subgrid of users and selecting Only Related Records . You can then add this quick view form to your invoice form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM