AnsweredAssumed Answered

Use Feature Layer Attribute as GP Service Input

Question asked by lloydbronn on Mar 6, 2017
Latest reply on Mar 8, 2017 by lloydbronn

I'm trying to click on a country layer and use the country name as input for a GP tool. I've done this with XY inputs from map clicks, but I'm having a lot of trouble getting the attribute from a feature. Do I need a query task? Here is my code snippet. When I add content to the infoWindow, it displays "Country: ${NAME}" so it's not pulling that attribute from the feature layer correctly.

 

var country = {};

var countriesLayer = new FeatureLayer("http://<ourserver>/arcgis/rest/services/Countries_Outline/MapServer/1");
          
          map.addLayer(countriesLayer);
          
          var content = "<b>Country</b>: ${NAME}";
             
          map.on("click", function(evt){
                         
          map.graphics.clear();
          var graphic = new Graphic(evt.mapPoint);
           
          map.graphics.add(graphic);
          map.infoWindow.setFeatures([graphic]);
           
            map.infoWindow.resize(200,200);     
          map.infoWindow.setContent(content);
          map.infoWindow.show(evt.mapPoint)
            map.infoWindow.setTitle("Forecast Reports");
           
        });
          
           
            var today = new Date();
            var todayISO = today.toISOString().slice(0,10).replace(/-/g,"");
           
            var link = domConstruct.create("a",{
                "class": "action",
                "id": "reportLink",
                "innerHTML": "Forecast Report", //text that appears in the popup for the link
                "href": "javascript: void(0);"
              }, query(".actionList", map.infoWindow.domNode)[0]);
          on(link, "click", function(){
           
            domAttr.set(dom.byId("reportLink"), "innerHTML", "Generating Report...");
           
            window.gp_chart = new Geoprocessor("http://<ourserver>/arcgis/rest/services/Generate_Forecast_Report/GPServer/CreateReport");
               
               var country = window.map.infoWindow.getSelectedFeature();
               
              var taskParams = {
                "Country":country
              };
                
              //window.gp_chart.execute(taskParams,gpChartResultAvailable,gpChartFailure);
                 window.gp_chart.execute(taskParams);

Outcomes