2

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!

Paul Haan
  • 101
  • 10
  • 1
    Is the tab collapsed by default? I remember reading somewhere that collapsed tabs are not rendered onload – jasonscript Nov 12 '18 at 05:59
  • @Jasonscript - I verified this morning that the section is visible by default. However, there was another method called by onLoad hiding that section in certain cases. I changed the order of execution so the getCustomView always fires first. The good news is the "addCustomView" error does go away! Unfortunately, the custom view is still not being used. It still shows all of the documents without the filters. One problem down, one to go! – Paul Haan Nov 12 '18 at 13:52
  • You have columns in your `layoutXml` that are not included in your `fetchXml` (e.g. "name", "createdon", "submittingparty"). Not sure if this is necessary but the comment in your code ("make sure to include these in the fetch query") suggests that it is :) – jasonscript Nov 13 '18 at 04:01
  • @jasonscript - Good catch. I updated the question accordingly. I inherited most of this code from the previous developer. I redid the FetchXml for my new view but didn't redo the layout. I removed one of the columns from the layout and updated the other two to match the FetchXml. It still has the same behavior. – Paul Haan Nov 13 '18 at 16:32
  • Are you sure your fetchxml is right? You've set your entityname as `confidentialdocument` This doesn't look like a system-entity but doesn't have a prefix (e.g. "new_") Did you build this view in Advanced Find? – jasonscript Nov 14 '18 at 00:50
  • 1
    Most of the names do indeed have a XXX_ prefix but I was preserving client anonymity. I removed the XXX_ as to not divulge the client information. The FetchXml in the actual javascript files was pulled directly from the customizations.xml in the exported solution file. – Paul Haan Nov 14 '18 at 14:07

0 Answers0