0

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: enter image description here

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.

1

Well after a bunch of digging (I'd been working on this problem long before I posted this question - hence the short time between my post and answer!), I found the issue. Turns out that when you create the feature layer, you take off the ID of the layer at the end of the URL and put dynamicLayer instead. Then everything worked (the rest of my code was fine).

The URL should look like this:

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

Additionally, I added a setDefinitionExpression method to the end of my code that worked perfectly. The "YearTreated" field is part of the table I joined to the polygon feature layer, and I was surprised I did not have to prefix it with the table name like HabitatManagement.dbo.MgmtAttrb.YearTreated Here is my example:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.