Skip to content
import VersioningState from "@arcgis/core/versionManagement/VersioningState.js";
Inheritance:
VersioningStateAccessor
Since
ArcGIS Maps SDK for JavaScript 4.30

This class provides functionality for managing versions in a versioned geodatabase. It includes methods for starting and stopping editing, changing versions, undoing and redoing edits, and retrieving version information.

See also
Example
const [utils, WebMap] = await $arcgis.import([
"@arcgis/core/versionManagement/versionAdapters/utils.js",
"@arcgis/core/WebMap.js"
]);
const webmap = new WebMap({
portalItem: { // autocasts as new PortalItem()
id: "e691172598f04ea8881cd2a4adaa45ba"
}
});
const versioningStates = await utils.createVersioningStates(webmap, false);

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

currentVersion

Property
Type
VersionIdentifier | Date

The current version.

currentVersionInfo

Property
Type
VersionInfo | null | undefined

Contains information on the current version.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

defaultVersionIdentifier

readonly Property
Type
VersionIdentifier

Contains the default version's name and guid.

featureServiceUrl

Property
Type
string

The absolute URL of the REST endpoint for the feature service housing the version management service. The URL may either point to a resource on ArcGIS Enterprise or ArcGIS Online.

isDefault

readonly Property
Type
boolean

If true, current version is the default version.

loaded

readonly Property
Type
boolean

Indicates whether the instance has loaded. When true, the properties of the object can be accessed. A WebMap is considered loaded when its WebDocument2D.layers and WebDocument2D.basemap are created, but not yet loaded.

Default value
false

loadError

readonlyinherited Property
Type
EsriError | null | undefined
Inherited from: LoadableMixin

The Error object returned if an error occurred while loading.

loadStatus

readonlyinherited Property
Type
"not-loaded" | "loading" | "failed" | "loaded"
Inherited from: LoadableMixin

Represents the status of a load() operation.

ValueDescription
not-loadedThe object's resources have not loaded.
loadingThe object's resources are currently loading.
loadedThe object's resources have loaded without errors.
failedThe object's resources failed to load. See loadError for more details.
Default value
"not-loaded"

loadWarnings

readonlyinherited Property
Type
any[]
Inherited from: LoadableMixin

A list of warnings which occurred while loading.

state

Property
Type
"lock-none" | "lock-read" | "lock-write"

The state of the current version.

Default value
"lock-none"

url

Property
Type
string

The absolute URL of the REST endpoint for the version management service. The URL may either point to a resource on ArcGIS Enterprise or ArcGIS Online.

usePersistentReadSessions

Property
Type
boolean

If the set to true, the current version will have a read lock. Additionally, when switching versions, the new current version will also have a read lock.

Default value
false

versionableItems

Property
Type
Collection<VersionAdapter>

Contains a collection of all versionable in the versioning state class.

versionInfos

Property
Type
VersionInfo[]

Contains list of all available versions.

versionManagementService

Property
Type
VersionManagementService

Contains metadata about the version management service.

Methods

MethodSignatureClass
fromJSON
inherited static
fromJSON(json: any): any
alterVersion(versionIdentifier: VersionIdentifier, props: AlterVersionParametersProperties): Promise<boolean>
cancelLoad
inherited
cancelLoad(): this
changeVersion(toVersion: VersionIdentifier | Date): Promise<Map<VersionAdapter, ServiceResult>>
deleteVersion(versionIdentifier: VersionIdentifier): Promise<boolean>
getVersionInfoExtended(): Promise<VersionInfoExtendedJSON | null | undefined>
getVersionInfos(refresh?: boolean): Promise<VersionInfo[]>
isFulfilled
inherited
isFulfilled(): boolean
isRejected
inherited
isRejected(): boolean
isResolved
inherited
isResolved(): boolean
load(options?: AbortOptions | null | undefined): Promise<this>
redo(): Promise<ServiceResult>
startEditing(): Promise<ServiceResult>
stopEditing(saveEdits: boolean): Promise<ServiceResult>
toJSON
inherited
toJSON(): any
undo(): Promise<ServiceResult>
when
inherited
when<TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameters
ParameterTypeDescriptionRequired
json
any

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
any

Returns a new instance of this class.

alterVersion

Method
Signature
alterVersion (versionIdentifier: VersionIdentifier, props: AlterVersionParametersProperties): Promise<boolean>

The alter operation allows you to change the geodatabase version's name, description, owner, and access permissions.

License

This method requires the feature service and version management service to be published with ArcGIS Enterprise version 11.2 or higher. Organization members must be assigned a license for the ArcGIS Advanced Editing user type extension to use this method.

Parameters
ParameterTypeDescriptionRequired
versionIdentifier

Identifier for a version.

props

Contains properties that will be altered.

Returns
Promise<boolean>

Returns true if version was altered successfully.

Example
const result = await versioningState.alterVersion(
{ name: "newVersion", guid: "{49C6AC87-CDA8-46D4-A79B-449105981209}" },
{
versionName: "versionName",
ownerName: "newOwner",
description: "newDescription",
access: "public"
}
);

cancelLoad

inherited Method
Signature
cancelLoad (): this
Inherited from: LoadableMixin

Cancels a load() operation if it is already in progress.

Returns
this

changeVersion

Method
Signature
changeVersion (toVersion: VersionIdentifier | Date): Promise<Map<VersionAdapter, ServiceResult>>

Method used to change a layer's version/moment or network's version/moment. Method allows changing version from named version to named version, or from default version to a moment and vice versa.

Parameters
ParameterTypeDescriptionRequired
toVersion

Incoming Version or Date.

Returns
Promise<Map<VersionAdapter, ServiceResult>>

Returns a map of VersionAdapter and ServiceResult.

Example
await versioningState.changeVersion(
{ name: "admin.version", guid: "{422D1B63-D795-4478-A4B1-AD6109377074}"}
);

deleteVersion

Method
Signature
deleteVersion (versionIdentifier: VersionIdentifier): Promise<boolean>

Deletes a version given the following parameters.

License

This method requires the feature service and version management service to be published with ArcGIS Enterprise version 11.2 or higher. Organization members must be assigned a license for the ArcGIS Advanced Editing user type extension to use this method.

Parameters
ParameterTypeDescriptionRequired
versionIdentifier

Identifier for a version.

Returns
Promise<boolean>

Specifies if the selected version was deleted.

Example
versioningState.deleteVersion({
name: "versionName",
guid: "{422D1B63-D795-4478-A4B1-AD6109377075}"
});

getVersionInfoExtended

Method
Signature
getVersionInfoExtended (): Promise<VersionInfoExtendedJSON | null | undefined>

Method used to get extended information about a version.

Returns
Promise<VersionInfoExtendedJSON | null | undefined>

Contains extended info about given version.

getVersionInfos

Method
Signature
getVersionInfos (refresh?: boolean): Promise<VersionInfo[]>

Returns all versions accessible to the currently logged-in user.

Parameters
ParameterTypeDescriptionRequired
refresh

If refresh is true, a new REST call will be made to the server to get the available versions.

Returns
Promise<VersionInfo[]>

Contains extended info about given version.

isFulfilled

inherited Method
Signature
isFulfilled (): boolean
Inherited from: EsriPromiseMixin

isFulfilled() may be used to verify if creating an instance of the class is fulfilled (either resolved or rejected). If it is fulfilled, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been fulfilled (either resolved or rejected).

isRejected

inherited Method
Signature
isRejected (): boolean
Inherited from: EsriPromiseMixin

isRejected() may be used to verify if creating an instance of the class is rejected. If it is rejected, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been rejected.

isResolved

inherited Method
Signature
isResolved (): boolean
Inherited from: EsriPromiseMixin

isResolved() may be used to verify if creating an instance of the class is resolved. If it is resolved, true will be returned.

Returns
boolean

Indicates whether creating an instance of the class has been resolved.

load

Method
Signature
load (options?: AbortOptions | null | undefined): Promise<this>

Triggers the loading of the version management service instance.

Fully loads the Version Management Service definition.

Parameters
ParameterTypeDescriptionRequired
options

Additional options.

Returns
Promise<this>

Resolves when the Feature Service is loaded.

redo

Method
Signature
redo (): Promise<ServiceResult>

This method redos the last edit made while in an edit session.

Returns
Promise<ServiceResult>

Specifies if redo was successful.

startEditing

Method
Signature
startEditing (): Promise<ServiceResult>

Using the specified session ID an exclusive lock is obtained for the session on the version. The exclusive lock can only be obtained if no other shared or exclusive locks are present and the session currently holds a shared lock. The exclusive lock ensures read and write isolation for the session holding the lock. The exclusive lock is downgraded to a shared lock by using the stopEditing operation.

Returns
Promise<ServiceResult>

Specifies if start editing was successful.

Example
await versioningState.startEditing();

stopEditing

Method
Signature
stopEditing (saveEdits: boolean): Promise<ServiceResult>

Using the specified session id, the exclusive lock for the version is downgraded to a shared lock. The saveEdits parameter specifies if the edits for the session should be saved (true) or discarded (false).

Parameters
ParameterTypeDescriptionRequired
saveEdits

If set to true edits will be saved, if false edits will not be saved.

Returns
Promise<ServiceResult>

Specifies if stop editing was successful.

Example
await versioningState.stopEditing(true);

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
any

The ArcGIS portal JSON representation of an instance of this class.

undo

Method
Signature
undo (): Promise<ServiceResult>

This method undos the last edit made while in an edit session.

Returns
Promise<ServiceResult>

Specifies if undo was successful.

when

inherited Method
Signature
when <TResult1 = this, TResult2 = never>(onFulfilled?: OnFulfilledCallback<this, TResult1> | null | undefined, onRejected?: OnRejectedCallback<TResult2> | null | undefined): Promise<TResult1 | TResult2>
Type parameters
<TResult1 = this, TResult2 = never>
Inherited from: EsriPromiseMixin

when() may be leveraged once an instance of the class is created. This method takes two input parameters: an onFulfilled function and an onRejected function. The onFulfilled executes when the instance of the class loads. The onRejected executes if the instance of the class fails to load.

Parameters
ParameterTypeDescriptionRequired
onFulfilled

The function to call when the promise resolves.

onRejected

The function to execute when the promise fails.

Returns
Promise<TResult1 | TResult2>

Returns a new promise for the result of onFulfilled that may be used to chain additional functions.

Example
// Although this example uses MapView, any class instance that is a promise may use when() in the same way
let view = new MapView();
view.when(function(){
// This function will execute once the promise is resolved
}, function(error){
// This function will execute if the promise is rejected due to an error
});