Select to view content in your preferred language

Function to grab the selection from another widget

2909
25
Jump to solution
05-24-2018 10:32 AM
MartinOwens1
Frequent Contributor

I've created a feature action in eSearch that can open another widget and send the selected featureSet, but I'm having trouble retrieving the selection from the other widget. I'm trying to use the selection from the eSearch wiget as an input for the results of another widget. Any help would be great!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Martin,

   So you said that the fields in the eSearch result layer are the same as what is the _this.config.pdfReportFields have you actually verified this? Just because they are based on the same layer the eSearch result layer will not have a field if you did not configure that field to be visible in the results.

View solution in original post

0 Kudos
25 Replies
KenBuja
MVP Esteemed Contributor

You should move this over to the Web AppBuilder Custom Widgets‌ space for more exposure.

RobertScheitlin__GISP
MVP Emeritus

Martin,

   The eSearch creates a new FeatureLayer that is added to the map from the search results so all you have to do is grab that layer from the map like you would any other layer in the map from your other widget.

0 Kudos
MartinOwens1
Frequent Contributor

Thanks Robert, I'll have to try it that way. Out of curoisity on my onExecute code below line 12 send the feature set to my Reporting widget and the getFeatures function?

onExecute: function(featureSet){
      var def = new Deferred();
       WidgetManager.getInstance().triggerWidgetOpen('Reporting')
                 .then(function(Reporting) {
      var featuresA = featureSet.features[0];
      var selectionLayerResponse = featuresA;
      //console.log("SelectionLayer="+ selectionLayerResponse);
      var featAttr = featureSet.features[0].attributes;
      console.log(featAttr);
       var featGeom = featureSet.features[0].geometry;
      //console.log(featGeom);
      Reporting.getFeatures(featureSet.features);
      var fName = [];
      var widget;
      fName[1] = featureSet.displayFieldName;
      fName[2] = featureSet.geometryType;
      //console.log('log: '+fName[1] +' ' + fName[2]);
        });
    }, 
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Martin,


  A feature set is just an array of graphics so get the layer and then use it’s graphics property.

0 Kudos
MartinOwens1
Frequent Contributor

Thanks for clarifying that for me. You said the eSearch creates a new FeatureLayer that is added to the map from the search results would you happen fo know the Id or name you are assigning it? It looks like "Search Results" is just the graphic because when I build the array using this.map.graphicsLayerIds it returns a result.

 array.forEach(this.map.layerIds, lang.hitch(this, function(layerId) {
          var layer = this.map.getLayer(layerId);
            if (layer.name === "Search Results"){
               
               addressPtsLayer = layer;
               
              console.log("This should return the Results" + addressPtsLayer);
}}));  
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Martin,


  A feature layer is also included in the GraphicsLayerIds since it extends from a GraphicsLayer.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

So you loop through the GraphicsLayetIds to find the eSearch layer and then grab its graphics property

0 Kudos
MartinOwens1
Frequent Contributor

Thanks for the help Robert. I would expect the following code to be writing to the console but it's not doing anything. Can you take a look?

    getFeatures: function() {
       this.generateButtonDiv.style.display = 'none';
      this.generateReportTable.style.display = 'none';
      this.clearButtonDiv.style.display = 'block';
      this.messageNode.innerHTML = '';
       
       var self = this;
       
       array.forEach(this.map.graphicsLayerIds, lang.hitch(this, function(layerId) {
          var layer = this.map.getLayer(layerId);
            if (layer.name === "Search Results"){
               addressPtsLayer = layer;
               
            console.log("This is a test" + addressPtsLayer);

         if (addressPtsLayer.graphics.length > 0) {
          self._zoomAndSelectFeatures(addressPtsLayer);
          self.reportFeatures = addressPtsLayer;
          self.messageNode.innerHTML = '';
          self.messageNode.appendChild(document.createTextNode('Number of selected features: ' + addressPtsLayer.graphics.length));
          self.generateButtonDiv.style.display = 'block';
          self.generateReportTable.style.display = 'block';
          self.clearButtonDiv.style.display = 'block';
          self.queryButtonDiv.style.display = 'none';
        }  

   }})); 
   },
0 Kudos
MartinOwens1
Frequent Contributor

Nevermind that code is working. The issue I'm having is what happens after this function. I'm using 

self.reportFeatures = addressPtsLayer; in a seperate function to generate a report but it's not getting the features for some reason. I'm going to have to look into it.
0 Kudos