Select to view content in your preferred language

Update feature attribute after adding to feature layer

719
2
03-05-2014 12:46 PM
AndrzejMilosz
Deactivated User
Hello,
In my editing application I use esri:Editor. I want to do next thing:
On creating new feature all attributes values except one should be added by user, the one should be added programmatically after feature created. I do not know what is the right way to added attribute value programatically.

I think I should call the method after FeatureLayer editsComplete and do applyEdits to update newly created feature.
I don't know the correct way to access the created feature.

My part of code is below, but the method trasy_editsCompleteHandler(event) is not called:

FeatureLaye definition:

<esri:FeatureLayer id="trasy"
                 editsComplete="trasy_editsCompleteHandler(event)"
   mode="snapshot"
   outFields="[Miesiace, Jak_czesto, Kierunek, Ile_minut, Poczatek, Koniec]"
   url="http://149.156.80.249:6080/arcgis/rest/services/daneRowerowe/trasy_miejsca_Krakow/FeatureServer/3"/>


And the code:

private var username:String = "newuser";
protected function trasy_editsCompleteHandler(event:FeatureLayerEvent):void
{
 const trasaUz:Object = {};
 trasaUz["Uzytkownik"] = username;
        var fSet:FeatureSet = new FeatureSet(event.adds);
 fSet.features[0].attributes = trasaUz;
 trasy.applyEdits(null, [fSet.features[0]], null);    
}


Thank you,
Andrzej
Tags (2)
0 Kudos
2 Replies
AndreasRuloffs1
Occasional Contributor
Hi,
you can use a FeatureLayerEvent.EDITS_STARTING event. This event is thrown before the edit is made permanently.
So you can manipulate the features before they are written in the database.
If you want to add only one value, maybe the easiest solution could be working with templates.
Hope this helps you,
Andreas Ruloffs

private function beforeEdit(event:FeatureLayerEvent):void
{
 // here you can manipulate the features you want to.
 event.featureLayer.applyEdits(event.adds,event.updates, event.deletes);
}
0 Kudos
AndrzejMilosz
Deactivated User
Thank you Andreas Ruloffs.

If you want to add only one value, maybe the easiest solution could be working with templates.

Yes, there is one value I want to add programmatically, it is user id, which is generated depending on date and time. I'm new in API for Flex. What are templates and how can I use them to achieve this?

Andrzej Mi�?osz
0 Kudos