Unable to update attribute alias of "Query Layers" in mxd using ArcPY

02-12-2018 03:22 AM
New Contributor II

I need to create a python script that can update attribute alias of "Query Layers" added in MXD.

arcpy.AlterField_management throws ERROR 001601: Failed to alter field alias. Failed to execute (AlterField).

Any Help or suggestions are appreciable!

6 Replies
MVP Legendary Contributor

Is Query Layers a layer in a Geodatabase table?


The error means that the alias is invalid and says to try another one


which may mean that the alias is a reserved word or it exists or a number of other reasons...

Try 'ABC' and see if that works as a test

Esri Esteemed Contributor

I wonder if Alter Field—Help | ArcGIS Desktop supports a Query Layer. Can you post you have tried?

New Contributor II

Query Layer is a geodatabase view. I have already tried alias name like "XYZ"

0 Kudos
MVP Legendary Contributor

As in the help link...

This tool provides the ability to rename fields or rename field aliases for any geodatabase table or feature class.

I suspect you are going to have to go directly to Modify a query layer

MVP Esteemed Contributor

By "geodatabase view," I interpret that as a database view that has been registered with a geodatabase.  Are you creating or working with a query layer defined against the geodatabase view above?  Query layers work best for enterprise databases that are not geodatabases, so if you have already registered a view with the geodatabase, why load it into ArcMap using a query layer instead of a regular layer?

Occasional Contributor

My experience has been there isn't much support for Query Layers in ArcPy.  A while back I needed to build a GP tool that would update query layer definitions based on database name/schema changes between Dev, Test and Prod environments, but there doesn't seem to be any support for that kind of thing in ArcPy. (I'm not sure there's even a reliable way to distinguish between query layers and regular EGDB layers in a map document.)  Ultimately ended up building the GP tool using ArcObjects, where there are interfaces like IQueryDescription.