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!
Solved! Go to Solution.
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.
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.
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.
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.