Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to get the primary key column of the Particular layer added in the Map. Usually 'FID' be found for a Shapefile Layer Source and OBJECTID found for a SDE source layer.

Is there any way to Identify which one is the primary key columns so that I can access those values.

I need to get this using ArcGIS JS API Version.3.3 and I am using ArcGIS Server 10.

share|improve this question
    
You can use "ObejectID".. I am using ObjectID column to display the attribute information of feature. For details please check ArcGIS Java Script API 3.3 samples –  Sunil Feb 5 '13 at 10:23

3 Answers 3

You could check it with Python...

import arcpy

layer= r"Put here the path to your data"
dscfc = arcpy.Describe(layer)

if dscfc.hasOID == True:
    print dscfc.OIDFieldName
else:
    print "No Primary Key found."

The OIDFieldName is the PK for the table.

share|improve this answer

You could loop through the fields for each layer and find the Object ID data type.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

    
Is there any example, or link to documentation you could provide? –  nagytech May 29 at 2:49

You could handle this using esri.request, or directly perform an AJAX request. Either way, you want to hit the layer's ArcGIS Server REST API.

Eg take the sample layer http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2

You can interrogate this via an AJAX request to http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2?f=json and examine the fields response, which contains:

{"name":"objectid","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}

Note the type indicates it's the OID field.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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