Javascript API Version 3.16
I have an issue with the applyEdits method on a Feature Layer when creating new features. I'm trying to get the GlobalID that is automatically generated. The REST response shows that the globalID did successfully get created but my attempts to get it via javascript keep resulting in 'undefined'. I'm wondering if there's a timing issue with when the globalID actually gets created?
I've tried this with two approaches, neither successful:
First approach
app.projectLayer.applyEdits([projectPoly], null, null).then(function(response) {
app.map.graphics.remove(projectPoly);
app.projectLayer.refresh();
});
app.projectLayer.on('edits-complete', function(result){
var projectObjId = result.adds[0].objectId;
var projects = app.projectLayer.graphics;
for (var i = 0, len = projects.length; i < len; i++) {
console.log(projects.attributes.GlobalID);
}
Second approach
app.projectLayer.applyEdits([projectPoly], null, null).then(function(response) {
var projectObjId = response[0].objectId;
var projects = app.projectLayer.graphics;
for (var i = 0, len = projects.length; i < len; i++) {
if(projects.attributes.OBJECTID == projectObjId){
console.log(projects.attributes.GlobalID);
}
}
app.map.graphics.remove(projectPoly);
app.projectLayer.refresh();
});
In both of these cases the console.log statement returns undefined. However if i set it to console.log(projects[i-1].attributes.GlobalID);, I get the GlobalID of the next-to-last feature, as expected. Why is it returning undefined for the newly created feature, especially when the REST response shows that the GlobalID was successfully created?