Select to view content in your preferred language

How to alter field?

712
4
Jump to solution
10-27-2022 04:35 PM
RejeanLabbe
New Contributor III

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.

0 Kudos
2 Solutions

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

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)

View solution in original post

RejeanLabbe
New Contributor III

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);

View solution in original post

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

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)

RejeanLabbe
New Contributor III

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.

0 Kudos
GKmieliauskas
Esri Regular Contributor

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 ?

0 Kudos
RejeanLabbe
New Contributor III

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);
0 Kudos