applyedits with setAttributes

4450
3
Jump to solution
02-20-2015 06:16 AM
IbrahimHussein
Occasional Contributor

Hey guys, first time using applyedits so Im a little confused on the process.

I have a graphic that id like to add to a feature layer. so I have the graphic and I am able to add just the graphic to the feature layer. but the user needs to add the attributes themselves otherwise everything is pretty much null. I am trying to set attributes before the apply edits that way a lot of the attributes can be set automatically, but I get an error that says

{code: 500, message: "Unable to complete operation.", details: Array[0], log: undefined, httpCode: 500…}

Code:

  map.graphics.on("click", function(evt) {
     console.log("click graphic");
     evt.graphic.setAttributes( {"OBJECTID":2312,"PARCELID":"1231233","STATUS":"RETIRED"});//test values
     FeatureLayr.applyEdits([evt.graphic],null,null,null,errCallback);
});


});   });

If I remove line 3 above (setAttributes) a dialog comes up to enter the attributes, but if I have the set attributes code I get that error. not sure I understand what the error is saying. 

0 Kudos
1 Solution

Accepted Solutions
IbrahimHussein
Occasional Contributor

Ok, figured it out. it was a scope issue.

placing the setAttributes after the applyedits fixed it, which makes sense. Thanks Ken, figured it out with your tip.

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

In my application, I'm setting the attributes of the feature with this syntax before I use the applyEdits method. The fields of the feature are "Priority", "Management", and "Criteria"

feature.attributes.Priority = priorityValue;
feature.attributes.Management = managementValue;
feature.attributes.Criteria = criteriaValue;
IbrahimHussein
Occasional Contributor

Thanks, you're getting me on the right track. But the current graphic only has these fields.

attributes:

     Object

     OBJECTID:

     created_date:

     created_user: ""

     last_edited_date:

     last_edited_user: ""

I noticed when I do setAttributes, they all get removed and the ones I set are the ones that are there.

0 Kudos
IbrahimHussein
Occasional Contributor

Ok, figured it out. it was a scope issue.

placing the setAttributes after the applyedits fixed it, which makes sense. Thanks Ken, figured it out with your tip.

0 Kudos