Specify attribute before creating feature - ArcPro SDK 2.7

1004
4
Jump to solution
02-11-2021 05:11 PM
PrashantKirpan
Occasional Contributor

Hi,

I'm trying to assign default attributes for newly created feature in featureService. I'm listening row created event and getting inspector of current edit template to assign value. But when feature is created for first time it doesn't assign value. After first feature is created value is getting assigned to attribute template and gets added to further features and works perfectly .

Code is as below :

 

 

 protected void OnRowCreated(RowChangedEventArgs args)
        {
            QueuedTask.Run(() =>
            {
                Inspector ins = ArcGIS.Desktop.Editing.Templates.EditingTemplate.Current.Inspector;
                ins["Field"] = "Some value";                
                ins.ApplyAsync();
            });

        }

 

 

 

Is there any way to assign value on or before creating feature first time? Any help would be appreciated.

-Prashant

0 Kudos
1 Solution

Accepted Solutions
KirkKuykendall1
Occasional Contributor III

Did you try 

args.Row["Field"] = "SomeValue";

?

View solution in original post

4 Replies
KirkKuykendall1
Occasional Contributor III

Did you try 

args.Row["Field"] = "SomeValue";

?

PrashantKirpan
Occasional Contributor

Thank you KirkKuykendall1,

Yes, Instead of adding values in attribute inspector I added in row as suggested and started working, here is my code:

 

  private void onRowCreateEvent(RowChangedEventArgs obj)
        {
            obj.Row["Field"] = "SomeValue";
        }

But in this case I can't see programmatically added value in Attribute template if template is open while editing.

Not sure if its okay to add values on both side simultaneously i.e. on row and attribute inspector together.  

-Prashant  

0 Kudos
PrashantKirpan
Occasional Contributor

Hi,

Code is perfectly working with feature class but having issue with feature service. See my below code for reference. 

I can see feature is getting added in feature layer attribute table in pro but doesn't sync online. I manually saved all edit's but still data is not appearing on feature service. After refresh or zoom-in/out feature gets cleated from pro attribute table also.

{
 var mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Contains("Map"));
 if (mapProjItem == null)
   return;

            QueuedTask.Run(() =>
            {
                var theMap = mapProjItem.GetMap();
                
                IEnumerable<FeatureLayer> featLayer = theMap.GetLayersAsFlattenedList().OfType<FeatureLayer>();
                foreach (FeatureLayer item in featLayer)
                { 
                   var layerTable = item.GetTable();
                   _rowCreateToken = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable);                        
             }

}

private void onRowCreateEvent(RowChangedEventArgs obj)
        {
            obj.Row["field"] = "Some Value";
 
}

-Prashant

 

 

0 Kudos
fpolia21
New Contributor II

You could also try to use ATTRIBUTE RULES 
https://pro.arcgis.com/en/pro-app/latest/help/data/geodatabases/overview/an-overview-of-attribute-ru...

../.."Attribute rules enhance the editing experience and improve data integrity for geodatabase datasets. They are user-defined rules that can be used to automatically populate attributes, restrict invalid edits during edit operations, and perform quality assurance checks on existing features.

Attribute rules are complementary to existing rules used in the geodatabase, such as domains and subtypes. For example, domains can be assigned to an attribute field to aid in the data collection process by providing a pick list of valid values for editors. Additionally, an attribute rule can be used to restrict values for an attribute field that are not part of the domain when performing a field calculation. After rules are added to a dataset, they can be evaluated as edits take place or at a later time."../..