I wrote a code to modify field aliases and there are multiple layers, some with great many columns, which require alias modification.
Below is the main part of the code which is supposed to be responsible for alias modificaiton. The issue is that after the process is run the aliases in on layers tables have not changed and I can't see why that is!
Layers is a list of layer names in the gdb. The new_alias is to replace the current alias of the columns.
with open(logpath, 'a') as cur:
for layer in layers:
layer = os.path.join(gdb, f"{fds}/{layer}")
print(f'Layer Name: {layer}', end=f'\n{"="*100}\n')
cur.write(f'\nLayer Name: {layer}\n{"="*100}\n')
columns = arcpy.ListFields(layer)
for field in columns:
if not field.required and len(field.name) > 20:
new_alias = field.aliasName.replace("_", " ").replace('PCT', '%').replace('plus', '+')
cur.write(f'Pre-processed Alias: {field.aliasName}\n')
arcpy.management.AlterField(in_table=layer
,field=field.name
,new_field_alias=new_alias)
print(f'Alias: {new_alias}\nField: {field.name}\n{"-" * 50}')
cur.write(f'Alias: {new_alias}\nField: {field.name}\n{"-" * 50}\n')
Would you please help me on why this is not working. I am using ArcGISPro?
Thanks in advance!