Select to view content in your preferred language

Variable string query outFields vs hard-coding

562
1
Jump to solution
04-20-2022 02:21 PM
GregoryBologna
Frequent Contributor

Why does variable string query outFields fail for FeatureLayer?

Example:

var queryFields = "FIELD1,FIELD2";

const query = mapLayerView.createQuery();
query.outFields = [queryFields]; This works!

const queryFeatureLayer = new FeatureLayer({
   url: url,
   outFields: ["FIELD1", "FIELD2"]
   // outFields: [queryFields] This will return error below
});

Error
esri.layers.support.fieldProperties] field-attributes-layer:invalid-field Invalid field FIELD1,FIELD2 found in outFields {layer: v, outFields: Array(1)}

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

Both FeatureLayer.outFields and Query.outFields expect string of arrays. Query.outFields accepting string of field names is not supported in the JS API and is working accidentally. 🙂

 

View solution in original post

0 Kudos
1 Reply
UndralBatsukh
Esri Regular Contributor

Hi there, 

Both FeatureLayer.outFields and Query.outFields expect string of arrays. Query.outFields accepting string of field names is not supported in the JS API and is working accidentally. 🙂

 

0 Kudos