getObjectId of Queryresult is null

297
1
09-22-2022 05:22 AM
WUE_BARAL
New Contributor II

Hello,
i have a problem with a graphic which i got through 2 different kind of requests. I cant perfrom the method getObjectId from the graphic. It always retruns null but in the attributes there is the objectId.

My first attempt was with the method queryFeatures directly on the featureLayer. The problem with this was in the version of the api 4.22.0 seems to be a issue with the error handling. The request failed randomly. But with the result of this attempt i could perfrom the method getObjectId.

the other two attempts was with esriRequest and executeQueryJSON.
With both of these request i got all features but i cant get the objectid although it is there.

I also tried to create a new Graphic with the layer from the request an i converted the result from esriRequest with fromJSON but i cant get the objectID.

best regards
nico

Tags (3)
0 Kudos
1 Reply
UndralBatsukh
Esri Regular Contributor

Hi there, 

FeatureLayer.queryFeatures() should work reliably. If you are seeing issues with it can you please provide me with a reproducible case? 

Graphic.getObjectId() method does return values from the `oid` field of the layer if one exists. Not all fields that are called objectid is the oid field of the FeatureLayer. You can get the actual oil field of your layer by checking FeatureLayer.objectIdField. This property returns the name of the layer's oid field and Graphic.getObjectId() reads values from this oid field.

I created this simple codepen app showcasing what I explained above: https://codepen.io/U_B_U/pen/gOzxNBa?editors=1000

Open the console to see the results of Graphic.getObjectId,  feature.attributes[layer.objectIdField] and feature.attributes.OBJECTID. As you can see the first two do return the values from the OID field while OBJECTID is just another field in the layer. Hope this makes sense.