Edit Related records in a datagrid

08-08-2012 07:53 AM
Occasional Contributor

I am new to flex so this is one of my first attempts. My widget selects a sign (from a Feature Layer) and the returns the related inspection data (from a Feature Layer called Inspection) in a grid. Ideally I want to be able to edit the attributes of the related inspection table in the data grid.

I have had a look at the edit related tables example and the attribute inspector but I am unsure which route to go down. Is it possible with the AttributeInspector to edit results from a relationship query in a grid?

E.g. We want to be able to select a site and view all of the outstanding maintenance issues related to it in a table, and assign each issue to a team and commment on it. Opposed to selecting each issue separatley to edit it.

Can anyone point me in the directon of a example of how to feature layer attributes within a datagrid?

Thank you


<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.events.*;
   import com.esri.ags.symbols.*;
   import com.esri.ags.tools.DrawTool;
   import com.esri.ags.geometry.Geometry;
    import mx.controls.Alert;
   import com.esri.ags.tasks.supportClasses.*;
   import com.esri.ags.layers.*;
   import com.esri.ags.geometry.Extent;
   import com.esri.ags.SpatialReference;
   import com.esri.ags.FeatureSet;
   import mx.rpc.AsyncResponder;
   import com.esri.ags.tasks.QueryTask;
   import com.esri.ags.events.FeatureLayerEvent;

   var graphicsLayer:GraphicsLayer;
   var sym:Symbol;
                        var flayer:FeatureLayer;

   private function centerMap():void 
    var point:MapPoint = new MapPoint(-118.24799,33.975004); 

   private function init ():void
    sym = new PictureMarkerSymbol(widgetIcon, 30, 30);
    graphicsLayer = new GraphicsLayer(); 
    graphicsLayer.symbol =sym; 

   private function widgetClosedHandler(event:Event):void
    graphicsLayer.visible = true;

   private function widgetOpenedHandler(event:Event):void
    graphicsLayer.visible = true;

   public function getlayers():void
    setMapAction(DrawTool.MAPPOINT, "Click Point",sym ,findsign, false); 
   private function findsign(event:DrawEvent):void
    var geom:Geometry = event.graphic.geometry;
    var pt:MapPoint = geom as MapPoint

    flayer = map.getLayer("Signs") as FeatureLayer
                  // find wells near the mouse click
                  var tol:Number = map.extent.width / map.width * 5;
                  var x:Number = pt.x;
                  var y:Number = pt.y;
                  var queryExtent:Extent = new Extent(x - tol, y - tol, x + tol, y + tol, map.spatialReference);
                  var thisSelectionQuery:Query = new Query();
                  thisSelectionQuery.geometry = queryExtent;
                  flayer.selectFeatures (thisSelectionQuery, FeatureLayer.SELECTION_NEW);
    flayer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE, flayer_selectionCompleteHandler)
    //Alert.show ("Test")

    private function flayer_selectionCompleteHandler(event:FeatureLayerEvent):void
                relatedDatagrid.dataProvider = null;
  //var objectID = new Number(event.features[0].attributes.ItemID);
                //Alert.show(event.features[0].attributes.OBJECTID + " #event.featurelength");
                // check the first return feature to see if it has any related features
                if (event.features.length > 0)
                    relquery.objectIds = [ event.features[0].attributes.OBJECTID ];
      //Alert.show(relquery.relationshipId + " relID");
                    flayer.queryRelatedFeatures(relquery, new AsyncResponder(onResult, onFault));
                    function onResult(relatedRecords:Object, token:Object = null):void
                        // get related records for the first feature
                        var fset:FeatureSet = (relatedRecords[event.features[0].attributes.OBJECTID]);
                        if (fset is FeatureSet)
                            relatedDatagrid.dataProvider = fset.attributes;
       //Alert.show("FeatureSet Created")
                            Alert.show("No related records for ItemID: #" + event.features[0].attributes.OBJECTID, "No related records");
                    function onFault(info:Object, token:Object = null):void
                        Alert.show(info.toString(), "queryRelatedFeatures Problem");
                    Alert.show("No wells found here, please try somewhere else.", "No features");


           <esri:RelationshipQuery id="relquery"

                                relationshipId="0" returnGeometry="true"/>

 <viewer:WidgetTemplate id="widgetTemplate" closed="widgetClosedHandler(event)" open="widgetOpenedHandler(event)">
  <mx:VBox autoLayout="false" width="200" height="200">
          <mx:Button click="centerMap()" label="Recenter Map" /> 
   <mx:Button click="activateTool()" label="Coordinates" paddingRight="25" />  
   <mx:Button click="getlayers()" label="GetRelatedInfo"/> 
  <mx:DataGrid id="relatedDatagrid" width="100%" height="100%">
              <mx:DataGridColumn dataField="ItemID" headerText="ItemID"/>
              <mx:DataGridColumn dataField="Condition" headerText="Condition"/>
   <mx:DataGridColumn dataField="Issue" headerText="Issue"/>
<mx:DataGridColumn dataField="Assigned_To" headerText="Assigned To"/>
Tags (2)
0 Kudos
3 Replies
Esri Contributor
Hi Vicky,  Hopefully this will help.  At 3.1, the API was enhanced to more easily accomplish editing related records.  Check out this sample / link.  If you had something else in mind, send us your feedback.


Doug Carroll, ESRI Support Services, SDK Tech Lead
0 Kudos
Occasional Contributor

Thank you for the link. Can you confirm whether or not the foreign key should be populated? (1:M relationship). The tables I have set up work in ArcMap and I can add a new record with the Relationship Inspector but I have to populate the foreign key manually.
0 Kudos
Occasional Contributor III
0 Kudos