Select to view content in your preferred language

Using join data source as source for feature layer

6998
3
Jump to solution
05-26-2015 08:13 AM
BethManghi
Regular Contributor

Does anyone have an example of using a join data source as the source for a feature layer?  I've successfully done this in the Flex API, but am having difficulty with the JS equivalent.  Here's a bit of my code

var rightTableSource = new LayerDataSource();
  rightTableSource.dataSource = new TableDataSource({
  workspaceId: "[workspaceid]",
  dataSourceName: "[tablename]"
});
var leftTableSource = new LayerMapSource({
  mapLayerId: 0
});
var dataSource = new JoinDataSource({
  joinType: "left-outer-join",
  leftTableKey: "Name",
  rightTableKey: "Name",
  leftTableSource: leftTableSource,
  rightTableSource: rightTableSource
});

var featureLayer = new FeatureLayer("[urltomapservice]/dynamicLayer", {
  id: "featureLayer",
  mode: FeatureLayer.MODE_ONDEMAND,
  source: dataSource,
  outFields: ["*"]
});

I don't get an error, so I assume it's working but the joined fields are not recognized.  I know this is possible with a dynamic map service layer.  Any ideas are much appreciated.  Thanks!

1 Solution

Accepted Solutions
BethManghi
Regular Contributor

I think I've figured it out.  I set up the layer data source incorrectly and used the wrong name for a property.

Here's my revised code:

var rightTableSource = new LayerDataSource();

  rightTableSource.dataSource = new TableDataSource({

  workspaceId: "[workspaceid]",

  dataSourceName: "[tablename]"

});

var leftTableSource = new LayerMapSource({

  mapLayerId: 0

});

var joinDataSource = new JoinDataSource({

  joinType: "left-outer-join",

  leftTableKey: "Name",

  rightTableKey: "Name",

  leftTableSource: leftTableSource,

  rightTableSource: rightTableSource

});

var layerDataSource = new LayerDataSource();

layerDataSource.dataSource = joinDataSource;

I tried to set the feature layer source as a JoinDataSource, when it really needs to be a Layer Data Source.  And the Layer Data Source has it's "dataSource" (not "source") as the JoinDataSource.  "Source" is the property name in the Flex API.  Got a bit crossed up!  This should work as the source for a feature layer and query task.

View solution in original post

3 Replies
ChrisSmith7
Honored Contributor

Beth,

I had this problem as well when initially developing our app. I ultimately went about binding data a different way... I am interested to see if anyone has info as well.

0 Kudos
BethManghi
Regular Contributor

Actually, I need to revised what I said.  With the code as I have it above, I get this error:

Error: Invalid source 'type' for dynamic layer with 'id': -1.

I looked at the API and there is a field for type (string) but I don't know what value to put there or whether that would even solve the problem.

0 Kudos
BethManghi
Regular Contributor

I think I've figured it out.  I set up the layer data source incorrectly and used the wrong name for a property.

Here's my revised code:

var rightTableSource = new LayerDataSource();

  rightTableSource.dataSource = new TableDataSource({

  workspaceId: "[workspaceid]",

  dataSourceName: "[tablename]"

});

var leftTableSource = new LayerMapSource({

  mapLayerId: 0

});

var joinDataSource = new JoinDataSource({

  joinType: "left-outer-join",

  leftTableKey: "Name",

  rightTableKey: "Name",

  leftTableSource: leftTableSource,

  rightTableSource: rightTableSource

});

var layerDataSource = new LayerDataSource();

layerDataSource.dataSource = joinDataSource;

I tried to set the feature layer source as a JoinDataSource, when it really needs to be a Layer Data Source.  And the Layer Data Source has it's "dataSource" (not "source") as the JoinDataSource.  "Source" is the property name in the Flex API.  Got a bit crossed up!  This should work as the source for a feature layer and query task.