Select to view content in your preferred language

Relates Relates Relates

2585
10
07-16-2010 10:22 AM
WillHughes1
Occasional Contributor II
Has anyone been successful getting relates to work in the Flex Sample Viewer?

What I want is for the user to be able to click on a fire hydrant and get information from a related table, such as fire flow test info.

If anyone has an example of this please point me to the sample or post it on the Flex API resource page.

Thanks.

-Will
Tags (2)
0 Kudos
10 Replies
MLowry
by
Occasional Contributor II
I would also like to know if anyone has gotten related results to show up in Flex SFV 2.0 using AGS 9.3.1
0 Kudos
ReneRubalcava
Frequent Contributor II
Relates won't work with 9.3.1 as the relationship is not recognized via the REST service.
0 Kudos
MLowry
by
Occasional Contributor II
Relates won't work with 9.3.1 as the relationship is not recognized via the REST service.


Right, but there's gotta be a way to do it, non-REST, somehow...
0 Kudos
WillHughes1
Occasional Contributor II
ok, so I am confused trying to navigate through the old and current forums. Here are some posts which might be useful from the archived forums. It sure would be nice if ESRI had just ported the old into the new. I still think the problem is REST won't support it where SOAP will, but it takes a lot of complex coding to build a SOAP app to handle relates. Not sure why this is so complicated. Let me know if anyone has success with the below posts.:D

Re: identify on related tables (ArcGis 9.1)
Author mark squires
Date Mar 23, 2009
Message Hi Janie,

That's correct, currently you cannot use related records for ArcGIS Server. There's an existing Enhancement Request for this, NIM010660.

I've added the following workarounds:

For a workaround regarding this process, you can use ArcScript samples:

he following ArcScripts provide a very effective and simple-to-install solution to this issue.

Identify with related Results (C#): http://arcscripts.esri.com/details.asp?dbid=15980
Identify with related Results (VB): http://arcscripts.esri.com/details.asp?dbid=15993

STEPS TO USE:

1) Publish an MXD with a table/FC relate or a relationship class as a map services

2) In Server Manager create a Web app connection to that layer through a "local" connection

3) Replace the Web app's "C:\Inetpub\wwwroot\\App_Code\MapIdentifyControl.cs" with the supplied "MapIdentifyrelated.cs" and restart the app.

NOTE: You don't even have to save it again in Server Manager. related info is visible in both pop-up and results if they are saved to the results pane

  Mark
(ESRI)

Re: Open new datagrid based on related values
Author Susan Mordy
Date Dec 02, 2009
Message I contacted ESRI technical support about querying related tables and they provided the following work around:

The work around is creating an external web service and pushing the related table out to the flex client that way. The general methodology is as follows:

1. Set up a custom service to hold the non-spatial table (use a WCF service if you are working with Microsoft)

*to created a non spatial map service, see: http://forums.esri.com/Thread.asp?c=158&f=2396&t=273651

1. Set up an identify using the flex querytask (you could start with the Identify sample)
2. Retrieve the attributes of the selected FC and store in a collection
3. Extract the foreign key used to link the 2 tables
4. Use that value to send to the custom service (using another query)
5. That query returns all the attributes from the non-spatial table matching the foreign key
6. You will want to build the results of both queries into an internal collection so that both sets of attributes are formatted the same.
7. Then use an info box or scroll box to display the collection.

The components in Flex that you can use to hit the custom web service is URLLoader or HTTPService.

Here are the links for those components:

http://www.adobe.com/livedocs/flex/3/langref/flash/net/URLLoader.html
http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html
0 Kudos
ReneRubalcava
Frequent Contributor II
** edit, just saw that last comment you posted above.
In my experience, a Web Service is quick, easy and usually a great tool for accessing external data.

You could create a web service using a .NET flavor of your choice that will query your SDE or any other db to simulate your relate. Pass it a name, id, whatever. It may be a little slow depending on size of results. I've used this method for a couple of years and it works fine. Typical method for above scenario.
Select graphic on map (you could also do this after getting Identify results if you'd like)
Pass attribute field value to web service
Use service response to populate List/DataGrid

A web service is pretty simple to set up in .NET and the code is pretty easy
http://msdn.microsoft.com/en-us/library/8wbhsy70.aspx

Simplest route is to return a DataTable and in flex that will be returned as an ArrayCollection that will look like event.result.Tables.<TableNameHere>.Rows
A benefit of doing the queries this way is that you can perform any JOINS/UNIONS or changing of field names that you may want to pass to your application to make things easier on yourself.
0 Kudos
MLowry
by
Occasional Contributor II
** edit, just saw that last comment you posted above.
In my experience, a Web Service is quick, easy and usually a great tool for accessing external data.

You could create a web service using a .NET flavor of your choice that will query your SDE or any other db to simulate your relate. Pass it a name, id, whatever. It may be a little slow depending on size of results. I've used this method for a couple of years and it works fine. Typical method for above scenario.
Select graphic on map (you could also do this after getting Identify results if you'd like)
Pass attribute field value to web service
Use service response to populate List/DataGrid

A web service is pretty simple to set up in .NET and the code is pretty easy
http://msdn.microsoft.com/en-us/library/8wbhsy70.aspx

Simplest route is to return a DataTable and in flex that will be returned as an ArrayCollection that will look like event.result.Tables.<TableNameHere>.Rows
A benefit of doing the queries this way is that you can perform any JOINS/UNIONS or changing of field names that you may want to pass to your application to make things easier on yourself.


Is there any way you could post the code you use to use this technique?
0 Kudos
ReneRubalcava
Frequent Contributor II
An example of the .NET web service accessing an SDE could look something like this
[WebMethod(Description = "Returns Flow Control History Details")]
public DataTable FlowControlHistory(String objectID)
{
 DataTable FlowTable = new DataTable();
 System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection("<your connection string here>");

 connection.Open();
 // build a sql expression to access your database data
 // using a passed OBJECTID from a feature in flex
 string strSQL = "SELECT DISTINCT t1.FLOWID " +
     "FROM sde.SSCOMPLEXFLOWCONTROLHISTORY as t1 " +
     "WHERE t1.OBJECTID = '" + objectID + "' " +
     "UNION " +
     "SELECT DISTINCT t2.FLOWID " +
     "FROM sde.SSFLOWCONTROLHISTORY as t2 " +
     "WHERE t2.OBJECTID = '" + objectID + "' " +
     "ORDER BY FLOWID;

 System.Data.OleDb.OleDbDataAdapter Adapter = new System.Data.OleDb.OleDbDataAdapter(strSQL, connection);

 Adapter.Fill(FlowTable);

 try
 {
  FlowTable.TableName = "Table";
 }

 finally
 {
  connection.Close();
 }

 return FlowTable;
}


Then in Flex, you'd do something like this.
protected var service:WebService;
protected var retry:uint = 0;

// send your Web Service WSDL to define a web service
public function setWsdl(value:String):void {
 service = new WebService();
 service.showBusyCursor = true;
 service.wsdl = value;
 service.addEventListener(FaultEvent.FAULT, WsdlFault, false, 0, true);
 service.loadWSDL();
}

protected function onWsdlFault(fault:FaultEvent, token:Object = null):void {
 // I always try to load a web service twice if I get a load error.
 // Just in case, my network can laugh at me sometimes
 retry++;
 if (retry < 2)
  service.loadWSDL();
 else {
  service.removeEventListener(FaultEvent.FAULT, WsdlFault);
  Alert.show("A Web Service has failed to load. Please close the application and try again.", "Error");
 }
}

// function that will call my web service
public function findRelatedFlowData(objectID:String):void {
 var responder:AsyncResponder = new AsyncResponder(onFlowDataResults, onFault);
 var request:AsyncToken = service.FlowControlHistory(objectID);
 request.addResponder(responder);
}

proteced function onFlowDataResults(result:ResultEvent, token:Object = null):void {
 var ac:ArrayCollection = result.result.Tables.Table.Rows;
 // do something with results here
}

protected function onFault(fault:FaultEvent, token:Object = null):void {
 // I always try to load a web service twice.
 Alert.show("A Web Service error has occurred.", "Error");
}


This has always worked for me, plus by using C# or VB.NET you get a bit more control over your query. The relates in the ESRI API are still great and I use them for large data dumps, but I still have a lot of these unique queries of my SDE.
0 Kudos
MLowry
by
Occasional Contributor II
How is a .NET web service set up in Flash Builder??

I have built a few apps using the Bing API with Visual Web Developer and used Web methods there for SQL queries, but I haven't integrated web methods into Flash Builder stuff yet? How is that done?
0 Kudos
SreeS
by
New Contributor
did you check these examples:

http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FeatureLayerQueryRelated

http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=FeatureLayerQueryRelatedMultiple

They are exactly what you need.

Has anyone been successful getting relates to work in the Flex Sample Viewer?

What I want is for the user to be able to click on a fire hydrant and get information from a related table, such as fire flow test info.

If anyone has an example of this please point me to the sample or post it on the Flex API resource page.

Thanks.

-Will
0 Kudos