Select to view content in your preferred language

ChangeVersion issue in Pro 3.2.1?

394
1
10-17-2024 02:41 PM
ScottDickison1
Emerging Contributor

I am trying to construct a start/stop editing button that will also switch to the appropriate version for the user that is logged in to the database. I am having an issue changing versions from SDE.Default to a child version of a child (if that makes sense). We have versions that are children of default and then I build editable private child versions off of those. Am I missing a step somewhere?  The Contents pane does not refresh to indicate that version change occurs. It doesn't error out - it just doesn't do anything.Using the Change Version tool in Pro  works.

using Version = ArcGIS.Core.Data.Version;
internal class StartStopEditing : Button
    {
        public Geodatabase transactionalGDB = null;
        protected async override void OnClick()
        {
            if (!Project.Current.IsEditingEnabled)
            {
                //Change or Create Version based on user name
                //Get the BOZAS layer from the map
                FeatureLayer pFL = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(x => x.Name == "BOZAS") as FeatureLayer;
                if (pFL != null)
                {
                    //Get the BOZAS layer geodatabase and from that the user name
                    Datastore ds = await Helper.GetDatastoreFromFeatureLayer(pFL) as Datastore;
                    await QueuedTask.Run(() =>
                    {
                        if (ds.GetConnectionString().ToUpper().Contains(Helper.desktopConfig.Transactional.ToUpper()))
                        {
                            transactionalGDB = ds as Geodatabase;
                            Helper.g_User = (ds.GetConnector() as DatabaseConnectionProperties).User;
                        }
                    });


                    string versionName = "BOZAS_" + Helper.g_User.ToUpper();
                    if (transactionalGDB != null)
                    {
                        await QueuedTask.Run(() =>
                        {
                            using (VersionManager versionManager = transactionalGDB.GetVersionManager())
                            {
                                Version fromVersion = versionManager.GetCurrentVersion();
                                //Check if Version Exists
                                IReadOnlyList<string> versionList = versionManager.GetVersionNames();
                                if (versionList.Contains(Helper.g_User.ToUpper() + "." + versionName))
                                {
                                    //If So, Change to It
                                    Version userVersion = versionManager.GetVersion(Helper.g_User.ToUpper() + "." + versionName);
                                    MapView.Active.Map.ChangeVersion(fromVersion, userVersion);
                                }
                                //If not, create it and then switch to it
                                else
                                {
                                    VersionDescription versionDescription = new VersionDescription() { AccessType = VersionAccessType.Private, Name = versionName, Description = "BOZAS Edit Version: " + Helper.g_User };
                                    Version parent = versionManager.GetVersion("JEFLIB.JEFLIB_E"); //This is set to Public
                                    Version newVersion = versionManager.CreateVersion(versionDescription, parent);
                                   
                                    MapView.Active.Map.ChangeVersion(fromVersion, newVersion);
                                }
                            }
                        });
                        //Enable Editing
                        await Project.Current.SetIsEditingEnabledAsync(true);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("No BOZAS layer found. Please insure that the BOZAS.aprx file is open in ArcGISPro and that the BOZAS layer has not been removed or renamed.", "No BOZAS Layer", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
                    return;
                }
            }

            if (Project.Current.IsEditingEnabled)
            {
                //Deal with saving edits before setting SetIsEditingEnabledAsync to false
                Project.Current.SetIsEditingEnabledAsync(false);
            }
        }
    }

 

0 Kudos
1 Reply
miyukioki
New Contributor

we have same problem. 

1.  Create new version

2.  map.ChangeVersion(default, newver)

3.  manually save projects. and exit ArcGIS Pro Application.

4.  Open saved Project.

5.  while( parent != null )  map.ChangeVersion( current, parent )

6.  Create new Version

7. map.ChangeVersion( default, newVer )

    but  version does not change to newVer. still sde.DEFAULT

 

 

0 Kudos