Select to view content in your preferred language

Get Fields ?

4460
18
10-13-2010 11:30 AM
Drew
by
Regular Contributor
Hello,
I am doing a small ESRI JS API project and don't use it too often so the library is new to me..
Anyways.. I cant find anyway to get field information.

I am trying to write a function that will determine what the the OBJECTID field name is based on its data type (esriFieldTypeOID)

The object is in the documentation (Field) but I can't find a way to get a field?

In the Flex API you can call a a function like so...


mapServiceLayer.getLayerDetails(...)



Please help me get a fields array.

Drew
0 Kudos
18 Replies
AlexGray
New Contributor
Hello,
I am doing a small ESRI JS API project and don't use it too often so the library is new to me..
Anyways.. I cant find anyway to get field information.

I am trying to write a function that will determine what the the OBJECTID field name is based on its data type (esriFieldTypeOID)

The object is in the documentation (Field) but I can't find a way to get a field?

In the Flex API you can call a a function like so...


mapServiceLayer.getLayerDetails(...)



Please help me get a fields array.

Drew


Drew,

I just learned about that myself not too long ago.. you can try taking a look at my work in progress.. http://www.co.frederick.va.us/planning/newmap1copy2.html

the layer referencing works.. I am a bit stuck on how to get the checkboxes to work properly though.. decided to go with checkboxes instead of link I had before..

Hope that helps..
Alex
0 Kudos
Drew
by
Regular Contributor
Alex,

I don't quite see any code that is pulling field information from a layer.
Maybe I am missing it just like how I can't find it in the ESRI doc's either..
Can you point me to a line number in your source?

Basically I want to get an array of Fields from a given layer (i.e. Parcels)

Drew
0 Kudos
AlexGray
New Contributor
Drew,

Sorry about that.. I miss read your question..

I did a little research and found a few things.. Although you might have already seen them..

In the JS api there is a property for esri.layers.featurelayer(objectIdField)

There is also a 'fields' property for featurelayer 'Field[]'.. the description for it states "The array of fields in the layer."

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/featurelayer.htm

Sorry, I couldn't provide you with any code samples.. as I am just learning programming/javascript now in order to make myself more marketable.. Hope what I provided was of some help..

Alex
0 Kudos
ReneRubalcava
Frequent Contributor II
I'm not too familiar with the Javascript API, so there may be a function for this built in, but you could pull the REST in JSON for any layer in a service like this
http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServ...

Than you can iterate through the "fields" element which is an array of objects that has a "type" element that will tell you what type the field is. I find that for some needs, it's just easier for me to make REST requests to get that kind of detailed information.
0 Kudos
Drew
by
Regular Contributor
Thanks Alex. I think I can work with this!

Drew
0 Kudos
AlexGray
New Contributor
Thanks Alex. I think I can work with this!

Drew


Drew,

Great.. Not a problem..

Alex
0 Kudos
Drew
by
Regular Contributor
After testing the "FeatureLayer" functionality this morning i realized that its not what i need.
Its more for overlaying the data.

Isn't there a way I can get the Fields and their data types from a specific feature class using the JS API?

Drew
0 Kudos
timgogl
New Contributor II
im new to the esri stuff myself, so this may or may not be of any use to you. have you looked at the task object? inside task is featureset which has the property fieldaliases :

fieldAliases  Object  Set of name-value pairs for the attribute's field and alias names.


dont know if that is exactly what you are looking for, but maybe it will move you along some more.
0 Kudos
AlexGray
New Contributor
Looks like you can get field dataypes from 'esri.layers.field.type'


type String The data type of the field.



http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm#jsapi/field.htm#type
0 Kudos