I try to alter a field size and alias using Geoprocessing Tool. Even if there is no error, the field is not altered.
List<object> oParams = new List<object>();
oParams.Add(oGeodatabase.GetPath().AbsolutePath);
oParams.Add(sTableName);
oParams.Add(sFieldName);
oParams.Add(sNewFieldName);
oParams.Add(sNewAlias);
oParams.Add("TEXT");
oParams.Add(60); // The actual field size is 50
var parameters = Geoprocessing.MakeValueArray(oParams);
var gpResult = Geoprocessing.ExecuteToolAsync("management.AlterField", parameters, null, CancelableProgressor.None, GPExecuteToolFlags.None);
Python script can be find here :
https://pro.arcgis.com/fr/pro-app/2.9/tool-reference/data-management/alter-field-properties.htm
I used the same syntax for AddCodedValueToDomain and it works, so I know that my geodatabase parameter is correct.
Solved! Go to Solution.
Hi,
You have wrong parameters list. TableName and geodatabase path must be combined together:
var parameters = Geoprocessing.MakeValueArray(Path.Combine(oGeodatabase.GetPath().AbsolutePath, sTableName), sFieldName, sNewFieldName, sNewAlias, "TEXT");
var gpResult = Geoprocessing.ExecuteToolAsync("management.AlterField", parameters, null, CancelableProgressor.None, GPExecuteToolFlags.None);
You can change field type if the input table is empty (does not contain records)
Thanks Gintautas.
Combining the geodatabase path and the table name did the trick.
However, I had another issue with my parameter list.
This is my final working code :
List<string> oParams = new List<string>();
oParams.Add(Path.Combine(oGeodatabase.GetPath().AbsolutePath, sTableName));
oParams.Add(sFieldName);
oParams.Add(sNewFieldName);
oParams.Add(sNewAlias);
oParams.Add(sFieldType);
if (sFieldType == "TEXT" || sFieldType == "BLOB") {
oParams.Add(sSize); // The field size must be the same or greater
}
var gpResult = Geoprocessing.ExecuteToolAsync("management.AlterField", oParams, null, CancelableProgressor.None, GPExecuteToolFlags.None);
Hi,
You have wrong parameters list. TableName and geodatabase path must be combined together:
var parameters = Geoprocessing.MakeValueArray(Path.Combine(oGeodatabase.GetPath().AbsolutePath, sTableName), sFieldName, sNewFieldName, sNewAlias, "TEXT");
var gpResult = Geoprocessing.ExecuteToolAsync("management.AlterField", parameters, null, CancelableProgressor.None, GPExecuteToolFlags.None);
You can change field type if the input table is empty (does not contain records)
Thank Gintautas. Unfortunately, this doesn't work. Have you tried it?
I tried multiple combinations but nothing works :
Path.Combine(oGeodatabase.GetPath().LocalPath, sTableName)
// or
oGeodatabase.GetPath().AbsolutePath + "/" + sTableName
I tried to change only the alias, but the change is not applied.
Yes, I have tried. It does not work on shapefile but works with gdb table. I have tried to change field name. alias name and length of TEXT field. There is some limitation with field type changing
Have you checked what you get from oGeodatabase.GetPath().LocalPath ?
Thanks Gintautas.
Combining the geodatabase path and the table name did the trick.
However, I had another issue with my parameter list.
This is my final working code :
List<string> oParams = new List<string>();
oParams.Add(Path.Combine(oGeodatabase.GetPath().AbsolutePath, sTableName));
oParams.Add(sFieldName);
oParams.Add(sNewFieldName);
oParams.Add(sNewAlias);
oParams.Add(sFieldType);
if (sFieldType == "TEXT" || sFieldType == "BLOB") {
oParams.Add(sSize); // The field size must be the same or greater
}
var gpResult = Geoprocessing.ExecuteToolAsync("management.AlterField", oParams, null, CancelableProgressor.None, GPExecuteToolFlags.None);