How to get the column names of a feature layer with JSAPI

1567
5
Jump to solution
11-11-2016 10:10 AM
JoeMinicucci
New Contributor II

I have a feature layer connected to a WAB map, with the following fields

  • OBJECTID ( type: esriFieldTypeOID , alias: OBJECTID )
  • LINE ( type: esriFieldTypeInteger , alias: LINE )
  • ROUTE ( type: esriFieldTypeInteger , alias: ROUTE )
  • SHAPE ( type: esriFieldTypeGeometry , alias: SHAPE )
  • SHAPE.STLength() ( type: esriFieldTypeDouble , alias: SHAPE.STLength() )

Utilizing the Feature Layer Object, is there any simple way to get a list of the field names? I'd rather not run a Query, but if I have to what is best way to only return 1 record with those field names?

Thank you for your time

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Joe,

Are you waiting for the FeatureLayer to load before you are checking the fields?

centerlineFeatureLayer.on("load", function(){
    console.info(centerlineFeatureLayer.fields);
});

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor
JoeMinicucci
New Contributor II

I tried accessing that object, Fields is null.. here is the logic (I confirmed the selectedCenterlineUrl is corrrect):

var selectedCenterlineUrl = this.HierarchyTableCenterlineSelect[this.HierarchyTableCenterlineSelect.selectedIndex].value;
var centerlineFeatureLayer = new FeatureLayer(selectedCenterlineUrl);

centerlineFeatureLayer gets created but fields is null..Why?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Joe,

Are you waiting for the FeatureLayer to load before you are checking the fields?

centerlineFeatureLayer.on("load", function(){
    console.info(centerlineFeatureLayer.fields);
});
JoeMinicucci
New Contributor II

Robert, thank you so much. This saved me hours of frustration and produced the intended result!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

0 Kudos