Set up customized field for editor tracking

1194
7
Jump to solution
06-04-2021 08:15 AM
YinghongLi1
Occasional Contributor

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./

 

1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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

Wolf_0-1622849657878.png

into this edit tracking enabled version:

Wolf_1-1622849706900.png

Then i did the same for a feature dataset:

Wolf_2-1622849732715.png

 

Wolf_3-1622849745264.png

and this enabled all feature classes in my feature dataset:

Wolf_4-1622849778993.png

 

 

View solution in original post

7 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You have to use a GP tool to 'Enable Editor Tracking', you can call the tool from the API:

Wolf_0-1622820048950.png

 

0 Kudos
YinghongLi1
Occasional Contributor

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.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I think I don't understand, the tool works for me:

Wolf_0-1622830459674.png

Wolf_2-1622830512919.png

 

then I get this result with the fields added:

Wolf_3-1622830543621.png

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.

 

 

0 Kudos
YinghongLi1
Occasional Contributor

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

 

YinghongLi1_0-1622831367917.png

 

0 Kudos
YinghongLi1
Occasional Contributor

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.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

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

Wolf_0-1622849657878.png

into this edit tracking enabled version:

Wolf_1-1622849706900.png

Then i did the same for a feature dataset:

Wolf_2-1622849732715.png

 

Wolf_3-1622849745264.png

and this enabled all feature classes in my feature dataset:

Wolf_4-1622849778993.png

 

 

YinghongLi1
Occasional Contributor

thanks.  this is what i need.  i will give it a try.

0 Kudos