Saving attribute to editable layer problem

Discussion created by msbsmith on Aug 30, 2011
Latest reply on Aug 31, 2011 by DSwingley-esristaff
Hello again,

I need to save a shape with attributes, unfortunately the field name in my code exists as a variable, and I can't get the setAttributes method to work with a variable for the field name, only by hard-coding the field name.  What I'm doing is applying the attribute to the graphic before saving, the below code works great every time:

var theValue = "Bob"
graphic.setAttributes({ "FirstName": theValue });

However the following code will not work, my shape gets saved but without the desired attribute:

var theField = "FirstName"
var theValue = "Bob"
graphic.setAttributes({ theField : theValue });

Can anyone please suggest how I can solve this issue?  Basically this comes from the fact the user is using a custom tool to save shapes to any editable layer, so the field names cannot be hard-coded, I have to get them from the layer they are trying to save to as variables.

Thank you.