JoinDataSource - what am I missing?

469
1
Jump to solution
02-21-2019 07:14 AM
MKF62
by
Occasional Contributor III

I'm looking to join a table to a polygon layer and I can't get the fields to transfer over. I'm sure there's something in my syntax that's messed up, but I can't figure out what it is. The goal of this process is to use a value from a field in the table to set the definition expression on the polygon layer (which I think I can do if the tables are joined?). It could be that I didn't create the workspaceId on the correct layer too... Or maybe I need to create a dynamic layer first? I'm utterly confused when it comes to dynamic layers.

This is what I currently have:

//Join habitat management attributes to the habitat management polygon layer
var joinDataSource = new JoinDataSource();
joinDataSource.joinType = 'left-inner-join';
joinDataSource.leftTableKey = "HabitatManagement.dbo.MgmtTracts.MgmtTractID";
joinDataSource.rightTableKey = "HabitatManagement.dbo.MgmtAttrb.MgmtTractID";
            
leftTableSource = new LayerMapSource({
      mapLayerId: 3
});

var rightTableSource = new LayerDataSource();
rightTableSource.dataSource = new TableDataSource({
      workspaceId: "hmgmtAttrb",
      dataSourceName: "HabitatManagement.dbo.MgmtAttrb"
});

joinDataSource.leftTableSource = leftTableSource;
joinDataSource.rightTableSource = rightTableSource;

var lyrDataSource = new LayerDataSource();
lyrDataSource.dataSource = joinDataSource;

//Add the habitat management tract feature layer
var hbMgmtTractFL = new FeatureLayer("https://stuff_here/rest/services/HabitatMonitoring/HabitatData/MapServer/3", {
       refreshInterval: 10,
       visible: false,
       source: lyrDataSource,
       outFields: ["*"]
});
hbMgmtTractFL.setMinScale(500000);
hbMgmtTractFL.setSelectionSymbol(selectionSym);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The JS runs without errors in the console, and I can see the source comes through:

When I look at the fields though, I only see the fields of the polygon layer listed.

In my server manager, I've set up the workspaceId on a connection with the HabitatManagement geodatabase instead of the HabitatMonitoring geodatabase. The map service I've set up the workspaceId on resides in the HabitatMonitoring folder. Would that cause an issue? The "MgmtTracts" and "MgmtAttrb" layer (the layers to be joined) reside in my HabitatManagement geodatabase which is why I created the workspaceId using that connection.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Occasional Contributor III

Well after doing a BUNCH more digging, I found this: Table source from ArcGIS Server | ArcGIS API for JavaScript 3.27 

It spelled out that you need to put dynamicLayer after your MapServer in the URL specified for the feature layer you're trying to create instead of the ID number. So when specifying the feature layer, the URL should look like this (the rest of the code was fine):

var hbMgmtTractFL = new FeatureLayer("https://stuff_here/rest/services/HabitatMonitoring/HabitatData/MapServer/dynamicLayer", { .....});

Additionally, I added a set definition expression method to the end of my code that worked just fine. I didn't even have to prefix the field with HabitatManagement.dbo.MgmtAttrb like I thought I would. The "YearTreated" field exists in the MgmtAttrb table.

hbMgmtTractFL.setDefinitionExpression("YearTreated = " + currentYear);

View solution in original post

0 Kudos
1 Reply
MKF62
by
Occasional Contributor III

Well after doing a BUNCH more digging, I found this: Table source from ArcGIS Server | ArcGIS API for JavaScript 3.27 

It spelled out that you need to put dynamicLayer after your MapServer in the URL specified for the feature layer you're trying to create instead of the ID number. So when specifying the feature layer, the URL should look like this (the rest of the code was fine):

var hbMgmtTractFL = new FeatureLayer("https://stuff_here/rest/services/HabitatMonitoring/HabitatData/MapServer/dynamicLayer", { .....});

Additionally, I added a set definition expression method to the end of my code that worked just fine. I didn't even have to prefix the field with HabitatManagement.dbo.MgmtAttrb like I thought I would. The "YearTreated" field exists in the MgmtAttrb table.

hbMgmtTractFL.setDefinitionExpression("YearTreated = " + currentYear);
0 Kudos