Change Version (Data Management)

Summary

Modifies the workspace of a layer or table view to connect to the specified version.

Usage

  • The tool only works with feature layers and table views.

  • The enterprise geodatabase connection file or feature service that is used to create the input feature layer or table view will not be edited by this tool. Only the open workspace of the input feature layer, table view, topology layer, parcel layer, utility network layer, or trace network layer is changed to connect to the specified version.

  • Transactional and historical views are supported.

Parameters

LabelExplanationData Type
Input Layer

The layer or table view that will connect to the specified version.

Note:

The sublayers of a topology layer, parcel layer, utility network layer, or trace network layer are not valid inputs.

Feature Layer; Table View; Topology Layer; Parcel Layer; Utility Network Layer; Trace Network Layer
Version Type

Specifies the type of version to which the input feature layer will connect.

  • Traditional versionConnect to a defined state of the database (traditional version).
  • Historical versionConnect to a version representing a defined moment in time, often specified by a time or historical marker.
  • Branch versionConnect to a branch version.
String
Version Name
(Optional)

The name of the version to which the input feature layer will connect. This parameter is optional if you're using a historical version.

String
Date and Time
(Optional)

The date of the historical version to which the input feature layer will connect.

Date
Include participating classes of controller dataset
(Optional)

Specifies whether the workspace of participating classes will also change.

The parameter is only applicable when the input layer is a topology layer, parcel layer, utility network layer, or trace network layer.

  • Checked—The version of the participating classes of the controller dataset will change if they are from the same workspace as the controller dataset. This is the default.
  • Unchecked—Only the version of the controller dataset will change.
Boolean

Derived Output

LabelExplanationData Type
Output Layer

The updated input dataset.

Feature Layer

arcpy.management.ChangeVersion(in_features, version_type, {version_name}, {date}, {include_participating})
NameExplanationData Type
in_features

The layer or table view that will connect to the specified version.

Note:

The sublayers of a topology layer, parcel layer, utility network layer, or trace network layer are not valid inputs.

Feature Layer; Table View; Topology Layer; Parcel Layer; Utility Network Layer; Trace Network Layer
version_type

Specifies the type of version to which the input feature layer will connect.

  • TRANSACTIONALConnect to a defined state of the database (traditional version).
  • HISTORICALConnect to a version representing a defined moment in time, often specified by a time or historical marker.
  • BRANCHConnect to a branch version.
String
version_name
(Optional)

The name of the version to which the input feature layer will connect. This parameter is optional if you're using a historical version.

String
date
(Optional)

The date of the historical version to which the input feature layer will connect.

Date
include_participating
(Optional)

Specifies whether the workspace of participating classes will also change.

The parameter is only applicable when the input layer is a topology layer, parcel layer, utility network layer, or trace network layer.

  • INCLUDEThe version of the participating classes of the controller dataset will change if they are from the same workspace as the controller dataset.
  • EXCLUDEOnly the version of the controller dataset will change.
Boolean

Derived Output

NameExplanationData Type
out_feature_layer

The updated input dataset.

Feature Layer

Code sample

ChangeVersion example 1 (Python window)

The following Python window script demonstrates how to use the ChangeVersion function in immediate mode.

import arcpy
from arcpy import env
env.workspace = r'c:\Connections\toolbox.sde'
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.street','RedlandsStreets')
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.streams','RedlandsStreams')
arcpy.MakeFeatureLayer_management(arcpy.SelectLayerByLocation_management("RedlandsStreams","WITHIN_A_DISTANCE","RedlandsStreets","100 Meters","NEW_SELECTION",'#'),
                                  'StreamsNearStreets','','','')
arcpy.ChangeVersion_management('RedlandsStreets','TRANSACTIONAL', 'TOOLBOX.proposedStreets2k9','')
arcpy.MakeFeatureLayer_management(arcpy.SelectLayerByLocation_management("RedlandsStreams","WITHIN_A_DISTANCE","RedlandsStreets","100 Meters","NEW_SELECTION",'#'),
                                  'NewStreamsNearStreets','','','')
ChangeVersion example 2 (stand-alone script)

Use the ChangeVersion function in a typical versioned analysis workflow.

# Name: ChangeVersion.py
# Description: Use the ChangeVersion tool in a typical versioned analysis workflow.
#              Quick check of additional streams within a pre-determined distance
#              of new proposed street development.

# Import system modules 
import arcpy
import sys
import os

# Set environments
arcpy.env.workspace = sys.path[0] + os.sep + "toolbox.sde"

# Create the layers
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.street','RedlandsStreets')
arcpy.MakeFeatureLayer_management(r'TOOLBOX.Redlands\TOOLBOX.streams','RedlandsStreams')

# Perform analysis on the Default version to determine
# current number of streams within 100 meters of streets.
selection1 = arcpy.SelectLayerByLocation_management("RedlandsStreams",
                                                    "WITHIN_A_DISTANCE",
                                                    "RedlandsStreets",
                                                    "100 Meters",
                                                    "NEW_SELECTION",
                                                    '#')
arcpy.MakeFeatureLayer_management(selection1,'StreamsNearStreets','','','')
print("Streams within 100 Meters of current streets: {}".format(
    arcpy.GetCount_management("StreamsNearStreets")[0]))

# Change to the development version
arcpy.ChangeVersion_management('RedlandsStreets',
                               'TRANSACTIONAL',
                               'TOOLBOX.proposedStreets2k9',
                               '')

# Perform the same analysis on the development version to see the effect of the proposed changes.
selection2 = arcpy.SelectLayerByLocation_management("RedlandsStreams",
                                                   "WITHIN_A_DISTANCE",
                                                   "RedlandsStreets",
                                                   "100 Meters",
                                                   "NEW_SELECTION",
                                                   '#')
arcpy.MakeFeatureLayer_management(selection2,'NewStreamsNearStreets','','','')
print("Streams projected to be within 100 Meters of streets after proposed street additions: {}".format(
    arcpy.GetCount_management("NewStreamsNearStreets")[0]))
ChangeVersion example 3 (stand-alone script)

Use the ChangeVersion function to change a feature service layer to a named branch version.

# Name: ChangeVersionBranchVersioning.py
# Description: Use the ChangeVersion tool to change the branch version of a feature service
#              layer that has the version management capability enabled.

# Import system modules 
import arcpy

# Sign into ArcGIS Enterprise
arcpy.SignInToPortal("https://myserver.mydomain.com/portal", 'portaladmin', 'my.password')

# Create a variable for the feature service URL
myFS = "https://myserver.mydomain.com/server/rest/services/BranchVersioningData/FeatureServer/0"

# Create the layers
arcpy.MakeFeatureLayer_management(myFS, 'myFSLayer')

# Change to a branch version named myVersion
arcpy.ChangeVersion_management('myFSLayer', "BRANCH", "portaladmin.myVersion")

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics