Is there any way to fetch attribute value using case insensitive attribute name? e.g. Following example is using objectIdField in the code.
Select with Feature Layer | ArcGIS API for JavaScript
inBuffer.push(feature.attributes[featureLayer.objectIdField]);
Not sure, how objectIdField is configured here but similar way, if I want to access any other field in the attributes regardless of the case then how can I do that?
Bhavin,
The case sensitivity will depend on the underlying database, for example if you are using a SQLServer database then the SQL statement is not case sensitive yet a file geodatabase is. What you can use is the upper or lower commands to match the case you require, eg:
Query: Wildfire Response Points (ID: 0)
Notice if you remove the upper command no results are returned
Regards
Anthony
In your example, upper is used with the attribute value. Did you intend to use it with the attribute name? My question is about attribute name mainly since that is used to fetch attribute value.
I am looking for following scenarios:
feature.attributes.created_user - this will return value in this case
feature.attributes.CREATED_USER - this won't return value in this case because CREATED_USER attribute is not existed. But created_user is existed.
Is there any way to configure particular field name constant (as given in following example) so, that can be referred with attributes while fetching attribute values? How objectIdField is configured here, any idea?
Select with Feature Layer | ArcGIS API for JavaScript
inBuffer.push(feature.attributes[featureLayer.objectIdField]);
the objectIdField is a property of the feature layer which is automatically set to the name of the field that contains the Object ID field for the layer. You will notice that there is not actually any field in the service that is called objectIdField. It is used to uniquely reference each feature in the layer.
Hi Bhavin,
You'll need another function which will do a case insensitive check on field name and return case sensitive field name which you can use to access the value. Refer below highlighted code changes.
function getCaseSensitiveAttributeName(fieldAliases, fieldName){
for (var key in fieldAliases) {
if (key.toUpperCase() === fieldName.toUpperCase()){
return key;
}
}
return "";
}
function selectInBuffer(response){
var feature;
var features = response.features;
var inBuffer = [];
//filter out features that are not actually in buffer, since we got all points in the buffer's bounding box
var mySensitiveField = getCaseSensitiveAttributeName(response.fieldAliases, <<Your Field Name>>);
for (var i = 0; i < features.length; i++) {
feature = features;
if(circle.contains(feature.geometry)){
inBuffer.push(feature.attributes[mySensitiveField]);
}
}
var query = new Query();
query.objectIds = inBuffer;
//use a fast objectIds selection query (should not need to go to the server)
featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
var totalPopulation = sumPopulation(results);
var r = "";
r = "<b>The total Census Block population within the buffer is <i>" + totalPopulation + "</i>.</b>";
dom.byId("messages").innerHTML = r;
});
}