OK now i understand.
Yea, i think when u do an applyedits, u need to wait till it get done, so u need to do callbacks o promises to handle the asyn issue.
So making a summary, u need to do:
After applyedits ends, rescue the objectid for the new object generated by the service.
After that, compare the objectid with the one u have already in the projects layer ( cuz it has to be updated already)
And then u get the globalid field.
I understand the flow like this, tell me if im wrong.
I could do something like this to resolve the problem:
function doAppEdits(projectPoly,callback){
app.proyectLayer.applyEdits([projectPoly],null,null).then((response)=>{
if (response[0].objectId){
callback(response[0].objectId);
return;
}
callback("NONE");
});
}
//here u will get the objectid number or "NONE" if doesnt exist.
var doneApplyEdits = doAppEdits(pp, (callback)=>{
//compare the array of project that u have with the objid that u already generated here
// if the layer is not refreshed maybe u will have to refresh it by force. I know there is a function to do that but i dont remember how was it.
var projectGlobalID = app.projectLayer.graphics.map(project =>{
if(project.attributes.OBJECTID == callback){
return project.attributes.GlobalID;
}
});
console.log("my global id for this project is:", projectGlobalID);
});