I am looking for a way to create a tool which will set up customized fields for editor tracking. However only thing I found is in TableDefinition, which has methods to get editor tracking fields. There are no methods which set the editor tracking fields.
I'd like to confirm that there is no object in SDK which are able to do this.
thanks./
Solved! Go to Solution.
Here is the tool in code. To try this out take the code snippet and replace the OnClick method of a 'test' button in your test add-in. Then change the fcName variable to match a feature class or feature dataset in your data.
protected override async void OnClick()
{
try
{
var fcName = $@"TestDataset"; // use either a feature class or a feature dataset
var createdBy = "CreatedBy";
var createdOn = "CreatedOn";
var modifiedBy = "ModifiedBy";
var modifiedOn = "ModifiedOn";
// use the default geodatabase
var gdbPath = CoreModule.CurrentProject.DefaultGeodatabasePath;
var fcFullSpec = System.IO.Path.Combine(gdbPath, fcName);
List<object> arguments = new List<object>
{
fcFullSpec, // Input dataset
createdBy, // Creator Field
createdOn, // Creation Date Field
modifiedBy, // Last Editor Field
modifiedOn, // Last Edit Date Field
true // Add fields
};
var r = await Geoprocessing.ExecuteToolAsync("EnableEditorTracking_management", Geoprocessing.MakeValueArray(arguments.ToArray()));
if (r.IsFailed)
{
MessageBox.Show($@"ExecuteToolAsync failed {string.Join(Environment.NewLine, r.ErrorMessages.Select(e => e.Text).ToArray())}");
}
MessageBox.Show ($@"{fcName} Enabled for Editor Tracking: {r.ReturnValue}");
}
catch (Exception ex)
{
MessageBox.Show($@"Exception: {ex}");
}
}
I used this snippet to turn this empty feature class
into this edit tracking enabled version:
Then i did the same for a feature dataset:
and this enabled all feature classes in my feature dataset:
You have to use a GP tool to 'Enable Editor Tracking', you can call the tool from the API:
that tool only works on default fields or SDE created fields. It does not allow user to select a field. I need one which is similar to the tool located at feature class property window but can be applied to whole dataset which contains more than one layer. of course the condition is that all the customized fields are same for the whole dataset.
I think I don't understand, the tool works for me:
then I get this result with the fields added:
I you want this to work on a whole dataset instead of just one feature class (or table) you have to iterate through all feature classes in that dataset and perform the action on each feature class.
This is what i got by running this tool. It did not give the option to select the field. I am using AG Pro 2.7
ok. I think i understand what you said. but the purpose to create a tool is to remove human entering each field. of course the condition is that all the layers in a dataset have the same tracking fields so human action is not needed. Tool will feed the field names.
thanks.
Here is the tool in code. To try this out take the code snippet and replace the OnClick method of a 'test' button in your test add-in. Then change the fcName variable to match a feature class or feature dataset in your data.
protected override async void OnClick()
{
try
{
var fcName = $@"TestDataset"; // use either a feature class or a feature dataset
var createdBy = "CreatedBy";
var createdOn = "CreatedOn";
var modifiedBy = "ModifiedBy";
var modifiedOn = "ModifiedOn";
// use the default geodatabase
var gdbPath = CoreModule.CurrentProject.DefaultGeodatabasePath;
var fcFullSpec = System.IO.Path.Combine(gdbPath, fcName);
List<object> arguments = new List<object>
{
fcFullSpec, // Input dataset
createdBy, // Creator Field
createdOn, // Creation Date Field
modifiedBy, // Last Editor Field
modifiedOn, // Last Edit Date Field
true // Add fields
};
var r = await Geoprocessing.ExecuteToolAsync("EnableEditorTracking_management", Geoprocessing.MakeValueArray(arguments.ToArray()));
if (r.IsFailed)
{
MessageBox.Show($@"ExecuteToolAsync failed {string.Join(Environment.NewLine, r.ErrorMessages.Select(e => e.Text).ToArray())}");
}
MessageBox.Show ($@"{fcName} Enabled for Editor Tracking: {r.ReturnValue}");
}
catch (Exception ex)
{
MessageBox.Show($@"Exception: {ex}");
}
}
I used this snippet to turn this empty feature class
into this edit tracking enabled version:
Then i did the same for a feature dataset:
and this enabled all feature classes in my feature dataset:
thanks. this is what i need. i will give it a try.