Definition Query in ArcGIS API for JavaScript 3.36 fails when using map service in ArcGIS Pro 2.8.3

118
0
10-07-2022 10:04 AM
LoriMcCormack1
New Contributor III

I cannot get the definition queries to work using dates in ArcGIS API for JavaScript 3.36 when using a map service that was published from ArcGIS Pro 2.8.3.  I am using ArcGISDynamicMapServiceLayer.

        //*********************************************
        // Build Definition Expression
        //*********************************************

        function buildDefExpr(paramOnDate, paramOffDate, paramSearchType, paramSpecial) {
            if (paramSearchType == "Today") {
                var dateExpr1 = "DisplayOnDate <= '" + paramOnDate + "' AND DisplayOffDate >= '" + paramOffDate + "'";
                var dateExpr2 = "";
                var dateAltExpr1 = "AlteranteRouteStartDate <= '" + paramOnDate + "' AND (AlternateRouteEndDate >= '" + paramOffDate + "')";
                var dateAltExpr2 = "";
                if (paramSpecial == "Trucks") {
                    dateExpr1 += " AND TravelImpact = 'No Truck Traffic'";
                }
            }
            else {
                var dateExpr1 = "((DisplayOnDate >= '" + paramOnDate + "' AND DisplayOnDate <= '" + paramOffDate + "') OR DisplayOnDate <= '" + paramOnDate + "') AND ";
                var dateExpr2 = "((DisplayOffDate >= '" + paramOnDate + "' AND DisplayOffDate <= '" + paramOffDate + "') OR DisplayOffDate >= '" + paramOffDate + "')";
                var dateAltExpr1 = "((AlteranteRouteStartDate >= '" + paramOnDate + "' AND AlteranteRouteStartDate <= '" + paramOffDate + "') OR AlteranteRouteStartDate <= '" + paramOnDate + "') AND ";
                var dateAltExpr2 = "((AlternateRouteEndDate >= '" + paramOnDate + "' AND AlternateRouteEndDate <= '" + paramOffDate + "') OR AlternateRouteEndDate >= '" + paramOffDate + "')";
                if (paramSpecial == "Trucks") {
                    dateExpr2 += " AND TravelImpact = 'No Truck Traffic'";
                }
            }
            // set layer definitions for site and route
            var defExpr_1_2 = "", defAltExpr = "";
            defExpr_1_2 = dateExpr1 + dateExpr2;
            layerDefinitions[travelImpactSiteIndex] = defExpr_1_2;
            layerDefinitions[travelImpactRouteIndex] = defExpr_1_2;    

            // set layer definition for alternate route
            defAltExpr = dateAltExpr1 + dateAltExpr2;
            layerDefinitions[altRouteIndex] = defAltExpr;

            // set layer definitions
            allTravelImpactsLayer.setLayerDefinitions(layerDefinitions);

            // set identify-layer definitions
            identifyLayerDefinitions[travelImpactRouteIndex] = defExpr_1_2;
            identifyLayerDefinitions[altRouteIndex] = defAltExpr;
            identifyParams.layerDefinitions = identifyLayerDefinitions;
        } // end function buildDefExpr()

Is there a 3.x version that will work?  Do I need to convert to 4.x?

Note:  Definition queries using dates failed in ArcGIS Pro 2.8.3 when I used Make Route Event layer from a view.  I had to import my map from ArcMap to get the definition queries to work.

0 Kudos
0 Replies