Fixes for linkedentities, inline filtering, and userData error with large numbers of results

Jun 29 at 10:27 AM
Hey all,

After some tweaks in the code I was able to fix a few things in the code.
  • Including linkedentities to the fetch filters
  • Making sure inline filtering in the view on linkedentity fields works.
  • Error in the retry mechanism in the code, where a result.userData is undefined error will pop up.
  • Displaying the map op a form based on a grid with related items.
Replace the LoadData function as follows:
function loadData() {
                var FetchXml = "";
                if (parent.effectiveFetchXml && Object.prototype.toString.call(parent.effectiveFetchXml) == "[object HTMLDivElement]") {  // Web
                    FetchXml = buildFetchXML(parent.effectiveFetchXml.getAttribute("value"));
                }
                else if (parent.$find("crmGrid")) {  // Outlook
                    FetchXml = buildFetchXML(parent.$find("crmGrid").GetParameter("effectiveFetchXml"));
                }
                else  // Retrieves the FetchXml using the provided viewId.  This is the only method that is technically supported, but it does not maintain user-filtered results.  This was added to support "Chart-Only" subgrids on Forms and Dashboards, but it also makes a good fallback if the unsupported methods fail.
                {
                    FetchXml = GetFetchXmlFromViewId(config.viewId);
                }
                
                dd_CRMService.RetrieveFetchXml(FetchXml, getPinData, function(error) { ShowErrorOnMap("There was a problem opening the record list"); });
            }
Replace the buildFetchXML function as follows:
function buildFetchXML(fetchXMLString) {
                /*var result = DataDescription.fetchXML;

                // TODO: use XPATH for this (dd_xmlparser.js)
                // 1. remove all attribute nodes
                // 2. add our address attributes
                // everything else stays the same, except maybe page/count

                if (!PresentationDescription.ShowAllRecords) {  // If showallrecords is true, then it will already be defaulted to "count=5000" and "page=1"
                    result = result.replace('count="250"', fetchXMLString.match(/count=".*?"/));
                    result = result.replace('page="1"', fetchXMLString.match(/page=".*?"/));
                }

                result = result.replace("<order/>", fetchXMLString.match(/<order.*?\/>/));
                result = result.replace("<filter/>", fetchXMLString.match(/<filter.*<\/filter>/));  // TODO: add support for link-entity filters

                return result;*/
                
                var result = DataDescription.fetchXML;
                var linkedrequest = fetchXMLString.match(/<link-entity.*<\/link-entity>/);
                if (linkedrequest != null && linkedrequest != "") fetchXMLString = fetchXMLString.replace(linkedrequest,"");

                if (!PresentationDescription.ShowAllRecords) {  // If showallrecords is true, then it will already be defaulted to "count=5000" and "page=1"
                    result = result.replace('count="250"', fetchXMLString.match(/count=".*?"/));
                    result = result.replace('page="1"', fetchXMLString.match(/page=".*?"/));
                }

                result = result.replace("<order/>", fetchXMLString.match(/<order.*?\/>/));
                result = result.replace("<filter/>", fetchXMLString.match(/<filter.*<\/filter>/)+linkedrequest);  

                return result;
            }
Replace the onGeocodeFail function as follows:
function onGeocodeFail(result) {
                if (result.request.userData.retryCount < 3) {
                    setTimeout(sendGeocodeRequest, 100, result.where, result.request.userData);  // Short delay and retry the failed record.
                    return;
                }

                geocodeComplete();
            }