get field type description from a layer, using no hard-coded values

07-07-2021 04:40 AM
New Contributor III

I am currently building a 'select by attributes'-GUI, similar to the one in ArcGIS Pro, in our web solutions using Web Appbuilder 3.xx, however, I am getting issues with fetching the field description of the layer. Primarily, I want to know the type of the fieldName. 

I've looked through almost any source regarding fields and feature layers, but there seems to be nothing that can help me. I've even tried to create a new feature layer object, using the URL from the layerNode in LayerStructure, however, it cannot give me the field description, specifically the type. It gives me a null / undefined when I call "getField(fieldName)" on the layer object.

Another approach that I tried to follow was to use the layerNode's popup object's methods, yet I am receiving a different field description compared to the one from the service URL. It almost seems like it has a different signature or has a different description completely. I really don't want to hard-code any of my layers or services into the widget. 


 this.layerStructure.traversal((layerNode) => {

let popupInfo = layerNode.getPopupInfo();
if (popupInfo != null) {
for (let index = 0; index < popupInfo.fieldInfos.length; index++) {
let fieldName = JSON.stringify(popupInfo.fieldInfos[index].fieldName);
// This doesn't exist, but it would have been nice if we could get the type just as easy as this..
// let fieldType = JSON.stringify(popupInfo.fieldInfos[index].fieldType);
// console.log(fieldType);

This will give the following result, if I were just to log the fieldInfos object:


Notice that it doesn't have a type, compared to when you look at one of the service url's field descriptions through a hyper-link in the browser:


Any  advice on how to get the type of the field using layerNode or similar?

0 Kudos
1 Reply
New Contributor III

Update - a step closer:


There's a field or attribute on the layerObject that shows all the information that I need from the rest service.

Output in text (marked with blue):

_fields: Proxy 
[[Handler]]: Object
[[Target]]: Array(13)
0: {name: "OBJECTID", type: "esriFieldTypeOID", alias: "OBJECTID", length: undefined, editable: false, …}
1: {name: "VARME_TYPE", type: "esriFieldTypeInteger", alias: "VARME_TYPE", length: undefined, editable: false, …}
2: {name: "ENERGI_DIS", type: "esriFieldTypeString", alias: "ENERGI_DIS", length: 9, editable: false, …}
3: {name: "ENERGI_DI1", type: "esriFieldTypeString", alias: "ENERGI_DI1", length: 80, editable: false, …}
4: {name: "ID1", type: "esriFieldTypeDouble", alias: "ID1", length: undefined, editable: false, …}
5: {name: "AJOUR", type: "esriFieldTypeString", alias: "AJOUR", length: 111, editable: false, …}
6: {name: "CREATED_USER", type: "esriFieldTypeString", alias: "CREATED_USER", length: 255, editable: false, …}
7: {name: "CREATED_DATE", type: "esriFieldTypeDate", alias: "CREATED_DATE", length: 8, editable: false, …}
8: {name: "LAST_EDITED_USER", type: "esriFieldTypeString", alias: "LAST_EDITED_USER", length: 255, editable: false, …}
9: {name: "LAST_EDITED_DATE", type: "esriFieldTypeDate", alias: "LAST_EDITED_DATE", length: 8, editable: false, …}
10: {name: "Shape__Area", type: "esriFieldTypeDouble", alias: "SHAPE.AREA", length: undefined, editable: false, …}
11: {name: "Shape__Length", type: "esriFieldTypeDouble", alias: "SHAPE.LEN", length: undefined, editable: false, …}
12: {name: "GLOBALID", type: "esriFieldTypeGlobalID", alias: "GLOBALID", length: 38, editable: false, …}
length: 13
__proto__: Array(0)

Originated from this line: console.log(layerNode._layerInfo.layerObject);

How do I get the access to the type of the _fields property when it is within a Proxy object? 

0 Kudos