Issues using a custom view on a Subgrid for a Lookup in Dynamics 365

2.4k views Asked by At

I am working on a form where visibility of a certain section is based on a specific field on the form. The section in question also has a subgrid ("WorkingDataRequestsGrid"). The logic for displaying the field is working fine. However, it is not filtering as expected. The subgrid uses a view I set up specifically for this function. It displays records from the same entity that have a specific type and status.

Properties of the Subgrid

On top of filtering by the type and status, the results should also be filtered by the relationship to the current case. For example, there are 3,500 documents in the system. Of those 3,500 documents, only 25 of them have the proper type/status combination. Of those 25, only three are for the same case. The inline lookup should display only those three files. It is still showing all 3,500. When I hit the look up more records button, it is not filtered by the custom view I set up.

Since the filter is using a join to the case (incident), I can't use the addCustomFilter or preSearch. I am limited to the "addCustomView" functionality due to the linked entity. When I set up the custom view based on the fetch XML from an advanced find, the page produces this error:

Alert for the Exception

The status field for the document has an onChange event that fires the following javascript:

function getCustomView() {
    try {
        var LookupControl = Xrm.Page.getControl("WorkingDataRequestsGrid");

        if (LookupControl != null) {
            var CaseId = Xrm.Page.getAttribute("confidentialdocuments").getValue()[0].id;
            var Casename = Xrm.Page.getAttribute("confidentialdocuments").getValue()[0].name;

            var fetch = "<fetch distinct='false' mapping='logical' output-format='xml-platform' version='1.0'>" +
            "   <entity name='confidentialdocument'>" +
            "       <attribute name='documenttitle'/>" +
            "       <attribute name='typeofrequest'/>" +
            "       <attribute name='createdby'/>" +
            "       <attribute name='respondingparty'/>" +
            "       <attribute name='noofquestions'/>" +
            "       <attribute name='dataresponseduedate'/>" +
            "       <attribute name='confidentialdocumentid'/>" +
            "       <order descending='false' attribute='documenttitle'/>" +
            "       <filter type='and'>" +
            "           <condition attribute='documenttype' value='{33F7488F-DE7C-E511-813B-1458D04E7900}' uitype='new_documenttype' uiname='Data Request' operator='eq'/>" +
            "           <condition attribute='documentstatus' value='413360000' operator='eq'/>" +
            "           <condition attribute='confidentialdocuments' value='" + CaseId + "' uitype='incident' uiname='" + Casename + "' operator='eq'/>" +
            "       </filter>" +
            "       <link-entity name='incident' alias='a_f409103f050fe71181091458d04dd6c8' link-type='outer' visible='false' to='confidentialdocuments' from='incidentid'>" +
            "           <attribute name='title'/>" +
            "       </link-entity>" +
            "   </entity>" +
            "</fetch>";

            //columns to display in the custom view (make sure to include these in the fetch query)
        var layout = "<layoutxml>" +
                "<grid name='resultset' icon='1' preview='1' select='1' jump='name' object='10013'>" +
                "    <row id='confidentialdocumentid' name='result'>" +
                "        <cell name='documenttitle' width='100'/>" +
                "        <cell name='a_f409103f050fe71181091458d04dd6c8.title' width='100' disableSorting='1'/>" +
                "        <cell name='createdby' width='100'/>" +
                "        <cell name='typeofrequest' width='100'/>" +
                "        <cell name='noofquestions' width='100'/>" +
                "        <cell name='respondingparty' width='100'/>" +
                "        <cell name='dataresponseduedate' width='100'/>" +
                "    </row>" +
                "</grid>" +
            "</layoutxml>";

            var viewId = "{00000000-0000-0000-0000-000000000009}";// add the randomly generated GUID for the view id
            var entityName = "confidentialdocument";//add the entity name
            var viewDisplayName = "Working Confidential Data Request Documents";// add the view display name

            //alert(viewId + " --- " + entityName + " --- " + viewDisplayName);
            Xrm.Page.getControl("WorkingDataRequestsGrid").addCustomView(viewId, entityName, viewDisplayName, fetch, layout, true);
        }
    }
    catch (error) {
        alert("Error in ConfidentialJs, Method Name: getCustomView(), Error: " + error.message);
    }
}

NOTE: I updated the "layout" XML using the xml from the Solutions Customizations.xml.

I had a few alert statements in the javaScript so I could see what was happening. When the field changes to the correct status, the javaScript function is fired. It fires during the onLoad event as well but the "LookupControl" comes up as null so it doesn't set the custom view.

I think I have just been looking at this issue too long. Chances are it is a very small issue I am just missing. I need a fresh set of eyes to see something I can't.

I need help with two issues:

  1. Any ideas as to why the filter will not use the specified view?
  2. Why does the onLoad event not have access to the look up control?

    The order of execution for several of the javascript methods set in the form properties caused the "Object does not support" error. One method was hiding the section so it couldn't be found. That has been fixed.

    After further review, the order of execution didn't actually fix the issue. It was never calling the addCustomView logic because it didn't find the "LookupControl." So, back to needing help on both issues!

Any help is greatly appreciated!

0

There are 0 answers