ChangeVersion

1373
8
Jump to solution
09-12-2019 09:20 AM
JimmyBowden
Occasional Contributor II

I have tried to use the Change Version (ArcGIS Pro 2.4 API Reference Guide) method on my current map and do not get the results I would expect.  I copied the code example directly into a button action. The UI doesn't show that the version has changed and there are no errors reported.  My Map has layers using the classic versioning model.  Is there something else that needs to be done to the UI to refresh?  Is there another way to get all the layers in a map to point to a different version?

#arcgisprosdk‌ 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

If you haven't done so already, I would take a look at toVersion.GetName() prior to calling Map.ChangeVersion() to verify that the value is expected.

Outside of that, I don't have any other ideas.  I set up an Oracle 12 environment that used classic versioning, and ran the sample code to switch the version from SDE.DEFAULT to the next version in the list (GDB.foo).  It all works correctly, and the Map refreshes afterwards.  

You may need to open an incident with tech support to figure out why this isn't working for you.

--Rich

View solution in original post

0 Kudos
8 Replies
RichRuh
Esri Regular Contributor

Jimmy,

At the risk of asking a stupid question, is the first layer in your map a feature layer that points to a versioned feature class?  That sample code only works if that is the case.

--Rich

0 Kudos
JimmyBowden
Occasional Contributor II

Sure got to start with the easy questions.  All the layers in my map (except basemap) are versioned pointing to an Oracle 12.1 enterprise geodatabase. 

0 Kudos
RichRuh
Esri Regular Contributor

Could you change the code to iterate through the versions on the geodatabase connection and verify that you are seeing all of the expected versions?  I'm trying to figure out if the problem is with versioning or with actually switching the map layers.

Thanks,

--Rich

0 Kudos
JimmyBowden
Occasional Contributor II

Here's the updated code I ran (changes in red).  The first time it ran I noticed that the first version was owned by another user but set to public.  I thought that might be an issue so I added the IsOwner and still got the same lack of result.  

await QueuedTask.Run(() =>
 {
 FeatureLayer flyr = MapView.Active.Map.GetLayersAsFlattenedList()
 .OfType<FeatureLayer>().FirstOrDefault(); //first feature layer
 Datastore dataStore = flyr.GetFeatureClass().GetDatastore(); //getting datasource
 Geodatabase geodatabase = dataStore as Geodatabase; //casting to Geodatabase
 if (geodatabase == null)
 return;

VersionManager versionManager = geodatabase.GetVersionManager();
 ArcGIS.Core.Data.Version currentVersion = versionManager.GetCurrentVersion();
//Getting all available versions except the current one
 IEnumerable<ArcGIS.Core.Data.Version> versions = versionManager.GetVersions()
 .Where(v => !v.GetName().Equals(currentVersion.GetName(), StringComparison.CurrentCultureIgnoreCase) && v.IsOwner());
 foreach (var item in versions)
 {
 System.Diagnostics.Debug.WriteLine(item.GetName());
 }
 //Assuming there is at least one other version we pick the first one from the list
 ArcGIS.Core.Data.Version toVersion = versions.FirstOrDefault();
 if (toVersion != null)
 {
 //Changing version
 MapView.Active.Map.ChangeVersion(currentVersion, toVersion);
 } 
0 Kudos
RichRuh
Esri Regular Contributor

If you haven't done so already, I would take a look at toVersion.GetName() prior to calling Map.ChangeVersion() to verify that the value is expected.

Outside of that, I don't have any other ideas.  I set up an Oracle 12 environment that used classic versioning, and ran the sample code to switch the version from SDE.DEFAULT to the next version in the list (GDB.foo).  It all works correctly, and the Map refreshes afterwards.  

You may need to open an incident with tech support to figure out why this isn't working for you.

--Rich

0 Kudos
JimmyBowden
Occasional Contributor II

Thanks for being checking.  I tried a different Oracle instance and it works great so it's just something with that specific instance.

JimmyBowden
Occasional Contributor II

The issue in the Oracle instance where this failed to work was that there was a version set to public but it's parent was set to private.  When the version manager is opened in ArcGIS Pro this version was marked red and version tools would not behave until this issue was cleared up.

RichRuh
Esri Regular Contributor

A-ha!  Thanks for following up.

0 Kudos