Update Feature Error

1684
22
Jump to solution
05-22-2019 05:28 AM
NadirHussain
Occasional Contributor II

Dear all,

 i am trying to update a feature using feature service.My geodatabase is versioned.below is my code 

var UpdateAttr = {
اسم_الشركة: test_2,
Mineral :validFeature.attributes.Mineral,
Geologist : validFeature.attributes.Geologist,
Duration : validFeature.attributes.Duration,
End_Date : validFeature.attributes.End_Date,//"",
Decision_Type :validFeature.attributes.Decision_Type,//"",
Location : validFeature.attributes.Location,//
Decision_Date : validFeature.attributes.Decision_Date,//"",
Decision_No : validFeature.attributes.Decision_Date,//"",
Visible_Code :validFeature.attributes.Visible_Code,//"",
Emirat_Code : validFeature.attributes.Emirat_Code,//
Mineral_Code : validFeature.attributes.Mineral_Code,//"",
Complex_Code : validFeature.attributes.Complex_Code,//"",
City_Code :validFeature.attributes.City_Code,//"",
Status_Code :validFeature.attributes.Status_Code,
Emirate : validFeature.attributes.Emirate,*/
Governorate : "ddd",
};
var UpdateValidLayer = new esri.layers.FeatureLayer(featureServiceValidURl);
var MyUpdateGraphic = new esri.Graphic(null, null, UpdateAttr);
var updateFeatures = [];
updateFeatures.push(MyUpdateGraphic);
UpdateValidLayer.applyEdits(null, updateFeatures, null, function (addResults, updateResults, deleteResults) {
  dynamicMapServiceLayer.refresh();
  console.log("Apply Edits Successfully:");
  alert("updated Successfully");
}, function (err) {
alert(err.message+"___"+err.code+"_________"+err.id);
console.log("Apply Edits Failed: ",err.message+err.code);
});

Always through error "Unabale to complete operation.Error Code is 400".i have this code many times in my other projects.But this time throwing error.

i also try to update feature using arcgis server webinterface.it works from the webinterface.so

Pls help.Thanks is advance.

0 Kudos
22 Replies
RobertScheitlin__GISP
MVP Emeritus

Nadir,

  Have you verified that validFeature is not null and is a graphic?

0 Kudos
NadirHussain
Occasional Contributor II

 Dear Robert,

 i check validfeature is not null and i replace this staetment with 

var feature = new esri.Graphic(null, null, UpdateAttr);

i also check feature is not null.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

  Remember I told you that would not work because you are trying to update so you need the original features ObjectId and geometry.

0 Kudos
NadirHussain
Occasional Contributor II

Robert,

  i tried with both ways.But its not work.

  var graphic=validFeature weather this statment is right or wrong but not throwing any error

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   I am lost then. When updating features in a FeatureService I just get the graphic (feature) I am updating and make my change to the attributes or geometry and then add that graphic to an array and pass that array to the update portion of applyEdits and it works.

0 Kudos
NadirHussain
Occasional Contributor II

Robert,

 Can you share your code so that i can match and figure out where is i am making mistake.

Thanks for your cooperation

0 Kudos
RobertScheitlin__GISP
MVP Emeritus
        var graphic = polyFeatLayer.graphics[polyFeatLayer.graphics.length - 1];  
  
        var currentDate = new Date();  
        var dateString = ((currentDate.getMonth() + 1) + "/" + currentDate.getDate() + "/" + currentDate.getFullYear());  
        var fixedDate = new Date.parse(dateString);  
  
        graphic.attributes["DT_ADDED"] = fixedDate;    
        polyFeatLayer.applyEdits(null, [graphic], null);
0 Kudos
NadirHussain
Occasional Contributor II

Dear Robert,

   the above code also not work.i think some problem in the code given below which i am using 

    var queryTask = new esri.tasks.QueryTask(RestServiceUrl + "/0");//Query For Valid Licences
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["*"];
query.where = "OBJECTID = '" + strLicsNumber + "'";
queryTask.execute(query, function (resultset) {
if(resultset.features.length>0){
 
validFeature = resultset.features[0]; ---->i am getting the feature here this line is right or wrong 
updateValidFeature(validFeature ,strHello,strHello1);

function updateValidFeature(validFeature,strHello,strHello1){
try { 
var UpdateValidLayer = new esri.layers.FeatureLayer(featureServiceValidURl);

if(validFeature!=null){
alert("ff");

}
validFeature["DISTANCE "]="100.00";

UpdateValidLayer.applyEdits(null,[validFeature],null, function (addResults, updateResults, deleteResults) {
console.log("Apply Edits Successfully:", updateResults);
alert("updated Successfully");
}, function (err) {
alert(err.message+"_________"+err.code+"_________"+err.details+"_______"+err);
console.log("Apply Edits Failed: ",err);
});
}
catch(Ex){
alert(Ex.message);
} 
////////////////////
}

pls check.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   Is the distance field a string type?

0 Kudos
NadirHussain
Occasional Contributor II

Robert,

its double.But i already changed in my code.the fallowing error coming

Cannot read property 'attributes' of undefined.

what is undefined in this small code.this make me crazy

0 Kudos