TypeError: Unable to get property 'geometry' of undefined or null reference TypeError: Unable to get property 'style' of undefined or null reference TypeError: Unable to get property 'style' of undefined or null reference
var extractMethod = "extractByPoly"; var extractMethod = "extractByCounty"; var extractMethod = "extractByUnit"; function myFunction() { //var extractMethod = "extractByPoly"; //var extractMethod = "extractByCounty"; //var extractMethod = "extractByUnit"; switch (extractMethod) { default: //function extractData() { //get clip layers var clipLayers = []; if (registry.byId("layer1").get("checked")) { clipLayers.push("SRA"); } if (registry.byId("layer2").get("checked")) { clipLayers.push("Burn"); } if (clipLayers.length === 0 || map.graphics.graphics.length === 0) { alert("Select layers to extract and draw an area of interest."); return; } var featureSet = new FeatureSet(); var features = []; features.push(map.graphics.graphics[0]); featureSet.features = features; var params3 = { "Layers_to_Clip": clipLayers, "Area_of_Interest": featureSet, "Feature_Format": registry.byId("formatBox").get("value") }; domStyle.set(loading2, "display", "inline-block"); gp.submitJob(params3, completeCallback, statusCallback2, function (error) { alert(error); domStyle.set(loading2, "display", "none"); }); //} break; case "extractByCounty": //function executeQueryTask(county) { var clipLayers = []; if (registry.byId("layer1").get("checked")) { clipLayers.push("SRA"); } if (registry.byId("layer2").get("checked")) { clipLayers.push("Burn"); } if (clipLayers.length === 0) { alert("No layers to clip, please select a layer you would like to clip..."); return; } var county = document.getElementById("sel_county").value var unit = document.getElementById("sel_unit").value var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/Counties/MapServer/0"); var query = new Query(); query.returnGeometry = true; query.outFields = ["NAME_PCASE"]; query.where = "NAME_PCASE = '" + county + "'"; query.outSpatialReference = map.spatialReference; queryTask.execute(query, function (featureSet) { var AOI = featureSet.features[0].geometry; var graphic = new Graphic(AOI); var features = []; features.push(graphic); var fSet = new FeatureSet(); fSet.features = features; var params = { "Layers_to_Clip": clipLayers, "Area_of_Interest": fSet, "Feature_Format": registry.byId("formatBox").get("value") }; domStyle.set(loading, "display", "inline-block"); gp.submitJob(params, completeCallback, statusCallback, function (error) { alert(error); domStyle.set(loading, "display", "none"); }); }); //} break; case "extractByUnit": //function executeQueryTask1(unit) { var clipLayers = []; if (registry.byId("layer1").get("checked")) { clipLayers.push("SRA"); } if (registry.byId("layer2").get("checked")) { clipLayers.push("Burn"); } if (clipLayers.length === 0) { alert("No layers to clip, please select a layer you would like to clip..."); return; } var unit = document.getElementById("sel_unit").value var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/Layers/MapServer/1"); var query = new Query(); query.returnGeometry = true; query.outFields = ["UNITCODE"]; query.where = "UNITCODE = '" + unit + "'"; query.outSpatialReference = map.spatialReference; queryTask.execute(query, function (featureSet) { var AOI = featureSet.features[0].geometry; var graphic = new Graphic(AOI); var features = []; features.push(graphic); var fSet = new FeatureSet(); fSet.features = features; var params2 = { "Layers_to_Clip": clipLayers, "Area_of_Interest": fSet, "Feature_Format": registry.byId("formatBox").get("value") }; domStyle.set(loading1, "display", "inline-block"); gp.submitJob(params2, completeCallback, statusCallback1, function (error) { alert(error); domStyle.set(loading1, "display", "none"); }); }); //} } }
Solved! Go to Solution.
Since your app is an internal application, it's really hard for us on the outside to troubleshoot what you're seeing. Your description makes me think there's a "cart in front of the horse" situation whereby part of your code is trying to use an object before it's returned from a query. In other words, "e" might be null because the code is accessing it before it gets populated. I've been tripped up by this type of situation before and it's frustrating to remedy.
I tried pulling out your dependencies on the code and from what limited things I can do, I'm not experiencing an error like you posted. Line 205 also doesn't seem to make sense in the code I have in front of me. Where is that? Is that in the addGraphic function we just added a post or two ago?