[GIS] add features to a featurelayer and save changes in the server

arcgis-javascript-apifeature-layerfeature-service

I am developping a web application with arcgis javascript api. I am using arcgis server 10.2.
I declared a featureLayer, the URL of this featureLayer is a feature service on my server.
Using a geoprocessing service, I am able to create features from the results of the service. I am able to add the features to the featureLayer I declared and show them in the map, but the problem is the changes made are not saved on the server.
this is the code sample:

 function displayResults(results, messages) {
    var flayer = new esri.layers.FeatureLayer("http://hamri-pc:6080/arcgis/rest/services/edt/FeatureServer/0", {
      mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
      outFields: ['*']
    });  
    var features = results[0].value.features;
    var theExtent = null;
    for (var f = 0, fl = features.length; f < fl; f++) {
        var feature = features[f];
        var attribs = feature.attributes;
            feature.setSymbol(normalpictureMarkerSymbol);
            feature.setInfoTemplate(infoTemplate);
                            flayer.add(feature);
                      flayer.applyEdits(feature,null,null);
                            map.addLayers([flayer]);
        }
    }

Does anyone have an idea of what should I do to save the features in the server?

Best Answer

Change this line

flayer.applyEdits(feature,null,null);

to

flayer.applyEdits(null, [feature], null);