Select to view content in your preferred language

Programmatically activate traditional versioning of a feature class

332
3
Jump to solution
04-25-2025 03:11 AM
MattHowe
Frequent Contributor

I have a fair number of feature classes in an enterprise geodatabase where I'd like to programmatically walk through each one and register it as versioned (traditional). As we're not using feature datasets, is the only way to do this manually or are there any ways to do it using arcpy for example?

MattHowe_0-1745575840855.png

 

0 Kudos
1 Solution

Accepted Solutions
AlfredBaldenweck
MVP Regular Contributor

Yup! Register As Versioned (Data Management)—ArcGIS Pro | Documentation

The documentation is a little confusing because dataset doesn't always mean "Feature Dataset"; it can also mean feature class or table.

View solution in original post

3 Replies
AlfredBaldenweck
MVP Regular Contributor

Yup! Register As Versioned (Data Management)—ArcGIS Pro | Documentation

The documentation is a little confusing because dataset doesn't always mean "Feature Dataset"; it can also mean feature class or table.

TonyAlmeida
MVP Regular Contributor

Something basic,

mport arcpy

# Enterprise geodatabase connection
workspace = r"***/***/***/enterprise.gdb"
arcpy.env.workspace = workspace

# List all feature classes 
feature_classes = arcpy.ListFeatureClasses()

# Loop through each feature class and register as versioned
for fc in feature_classes:
    try:
        full_path = os.path.join(arcpy.env.workspace, fc)
        print(f"Registering {fc} as versioned...")
        arcpy.RegisterAsVersioned_management(full_path, , "NO_EDITS_TO_BASE")  
    except Exception as e:
        print(f"Failed to register {fc}: {e}")

 

for editing tracking maybe try, https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/enable-editor-tracking.htm

# Editor tracking configuration
created_user = "CREATED_BY"
created_date = "CREATED_DATE"
edited_user = "LAST_EDITED_BY"
edited_date = "LAST_EDITED_DATE"

fields = [f.name for f in arcpy.ListFields(full_fc)]
tracking_enabled = arcpy.Describe(full_fc).editorTrackingEnabled

if not tracking_enabled:
    arcpy.EnableEditorTracking_management(
        in_dataset=full_fc,
        creator_field=created_user,
        creation_date_field=created_date,
        last_editor_field=edited_user,
        last_edit_date_field=edited_date,
        add_fields="ADD_FIELDS",
        record_dates_in="UTC"
    )

 

0 Kudos
MattHowe
Frequent Contributor

Thanks @TonyAlmeida . I'm ok with the code, it just wasn't clear as to whether it could be done at the feature class level as the documentation says feature dataset or table view. Thanks again!

0 Kudos