AnsweredAssumed Answered

Issue with callbacks while uploading multiple graphics to "apply edits" inside of For Loop in JS API 3.23

Question asked by amrutabildikar5 on Apr 17, 2018
Latest reply on Apr 18, 2018 by kenbuja

Hi All,

I have 2 feature layers added in my map:1 point layer(coming from Mapservice) and 1 polygon feature layer(Which is coming from feature service). I would like to upload the polygon geometries build up from Json to associated point feature. so Point ID will be stored in associated polygon geometries and it will get passed to apply edits call. I am following below mentioned steps:

1. build featureset from input JSON

2.Loop featureset ,Inside of "for loop", taking one feature at a time, checking if it's geometry is associated with point geometry which is selected on map(checking if point geometry is inside of polygon geometry)

3. if step 2 is successful, pass that feature to "apple edit" BUT Apply edit is async call and taking it's own time and loop is not getting executed for all the feature geometries

4. If I put break point at Callback function from "apply edit calls" is not working.


Relevant code:--------------

if (featureSet && featureSet.features && selectedResource) {
//To-do:check if resource point is inside of outline geometry

for (var i = 0; i < featureSet.features.length; i++) {
featureSet.features[i].attributes["additionalinformation"] = selectedResourceID;
var attribs = featureSet.features[i].attributes;

featureSet.features[i].spatialReference = featureSet.spatialReference;
boolContains = IfContains(featureSet.features[i], selectedResource)
if (boolContains) {
var wgs84 = new esri.geometry.Polygon(featureSet.features[i].geometry);
var graphic = new esri.Graphic(wgs84, symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NULL,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([112, 112, 112]), 1), new Color([136, 136, 136, 0.25])), attribs);

if (graphic.geometry == null) {
console.log("Graphic geometry is null");
else {

//Apply Edit call
OutlineLayer.applyEdits([graphic], null, null).then(function (addResults, updateResults, deleteResults)
{ alert('Addsuccess', addResults); }).then(function (error)
{ console.log('error: '+ error); });
OutlineLayer.on("edits-complete", onComplete);
else {
alert("Browsed Outline is not associated with the selected resource geometry");




in above code, I have formatted(Bold and Italic) the callback function with addResults, update and.. How to ensure in this function that loop is getting honored and one by one feature will get uploaded via apply edits?


I am working with ArcGIS JS API 3.23.