Setting an attribute value on feature creation

984
6
11-24-2010 07:40 PM
mdonnelly
Esri Contributor
Hi,

I'm using the template picker to create features from a given template. What I want to be able to do is to automatically set the value of an attribute for that feature. The value of the attribute will only be known at the time it is created.

Basically, the web application I am building receives an id that I need to assign to each feature created.

I've had a look through the forums and samples but can't see exactly how to go about this.

Regards,

Mark
Regards,
Mark
0 Kudos
6 Replies
mdonnelly
Esri Contributor
OK, I've managed to push the attribute value into the graphic. However it then doesn't render the graphic that has just been created by the feature template picker. Any ideas?

var ft0 = new esri.layers.FeatureLayer("http://172.16.25.71/ArcGIS/rest/services/necma_wod2/FeatureServer/0",{
          mode: esri.layers.FeatureLayer.MODE_ONDEMAND, 
          outFields: ['*']
        });
dojo.connect(ft0, "onBeforeApplyEdits", addAttributeValues);
.
.
.
function addAttributeValues (adds, updates, deletes){
          for (i in adds){
              adds.setAttributes({"ARID":arid,});
              adds.visible = true;
              adds.show();
              //alert(adds.getContent());
          }
      }
Regards,
Mark
0 Kudos
KellyHutchins
Esri Frequent Contributor
Mark,

Here's a code snippet that worked for me:

          
dojo.connect(layer,"onBeforeApplyEdits",function(adds,updates,deletes){
            dojo.forEach(adds,function(add){
              add.attributes.symbolid = new Date().getTime().toString();
            });
          });
0 Kudos
mdonnelly
Esri Contributor
Thanks so much, that worked a charm.

The behaviour of setAttributes is very strange!
Regards,
Mark
0 Kudos
timgogl
New Contributor II
i believe that with dojo at least 'setAttribute' is depricated.
0 Kudos
RyanTwilley
New Contributor
Hi there,

Nice solution, but things still aren't working for me. According to the edit callback, everything is working just fine; attributes are being sent to the server, and the 'success' field in the 'addResults' object (in the edit callback) is always returns true, BUT the instances being created in my geodatabase never have any attribution set. I've tried updating after the add also, and get the same results. The process reports that everything went smoothly, but the database does not reflect that at all.

Any ideas?

Ryan
0 Kudos
RyanTwilley
New Contributor
So, I had forgotten that I marked the columns that I was trying to set as 'Read-only' in the attribute table in ArcMap before I published the map service. Oops!
0 Kudos