Table to Domain with Filter

3166
3
04-16-2015 10:13 AM
ToddHenry1
Occasional Contributor

I have a table with a list of employees that I would like to split into three separate domains based on their job description which are listed in the table.  Is there a way (probably with python) to automate the creation of those domains so that I could use the Table to Domain tool, but with only the appropriate subset.

Right now, I'm using the Create Domain and AddCodedValueToDomain to do this manually for each person.

Thanks.

0 Kudos
3 Replies
OwenEarley
Regular Contributor

I would use the Make Table View tool with an expression to select your users into groups - then use the Table to Domain tool to create the domains.

0 Kudos
OwenEarley
Regular Contributor

Something like this should work:

import arcpy

# script parameters: 
userTable = r"G:/Temp/GeoNet/TableToDomain/Users.gdb/Users"
domainTargetGdb = r"G:/Temp/GeoNet/TableToDomain/Users.gdb"

# Create Admins Domain
admins = arcpy.MakeTableView_management(userTable,"Admins",""""GroupName" = 'Editor'""")
arcpy.TableToDomain_management("Admins","Username","Username",domainTargetGdb,"Admins","Admin Users","REPLACE")

# Create Editors Domain
editors = arcpy.MakeTableView_management(userTable,"Editors",""""GroupName" = 'Editor'""")
arcpy.TableToDomain_management("Editors","Username","Username",domainTargetGdb,"Editors","Editor Users","REPLACE")

# Create Viewers Domain
viewers = arcpy.MakeTableView_management(userTable,"Viewers",""""GroupName" = 'Viewer'""")
arcpy.TableToDomain_management("Viewers","Username","Username",domainTargetGdb,"Viewers","Viewer Users","REPLACE")

You will need to change the source of the users table and the target geodatabase as well as the query expressions used to select your user groups in the Make Table View tool.

0 Kudos
ToddHenry1
Occasional Contributor

Thanks. That makes a lot of sense.

0 Kudos