You are viewing limited content. For full access, please sign in.

Question

Question

How to Create Versions in LFSO09?

asked on November 17, 2015 Show version history

Hi,

I’m having some difficulty adding a group of documents as versions to some original document. We are migrating documents from another ECM system and we need to preserve versioning. Sometimes there are, say, 4 versions of a document, each having its own TIFF file. So, I’m creating these documents in LF first, and then trying to add them as versions to the original (earliest) document.

 

Here’s part of the relevant code:

 

//some other code ….

if (doc.Versions > 1)
   {
    //Retrieve versions info from db
    dtVersions = otherCMSDB.GetDocumentVersions(doc.Number, doc.EarliestVersionID);
    int versionNo = 2;

    foreach (DataRow dr in dtVersions.Rows)
    {
         int versionTocID = CreateDocument(doc, ParentFolder, true, LFVolume, TemplateName, db);
         string notes = (Convert.IsDBNull(dr["AUTHOR"]) ? "" : "Author: " + dr["AUTHOR"].ToString() + ". ") +
                                (Convert.IsDBNull(dr["VERSION_LABEL"]) ? "" : "Version Label: " + dr["VERSION_LABEL"].ToString());

         AddVersion(TocID, versionTocID, versionNo, notes, db);
                            versionNo++;
     }
                        
   }

//some other code ….

public void AddVersion(int origTocID, int verTocID, int version, string notes, LFDatabase db)
        {
            LFDocument Doc = null;
            LFDocument VerDoc = null;
            LFVersionData OrigVData, NewVData;

            try
            {

                Doc = (LFDocument)db.GetEntryByID(origTocID);

                LFVersionControlInfo vControlInfo = Doc.VersionControlInfo;
                if (!vControlInfo.IsVersionControlled)
                {
                    vControlInfo.PutUnderVersionControl();
                }
                
                OrigVData = (LFVersionData)Doc.VersionData;

                // Create new VersionGroup if needed
                LFVersionGroup VGroup;
                if (OrigVData.Version == 0)
                {
                    VGroup = OrigVData.AddToNewVersionGroup();
                }
                else
                {
                    VGroup = OrigVData.VersionGroup;
                }

                // Retrieves second version.
                VerDoc = (LFDocument)db.GetEntryByID(verTocID);
                NewVData = (LFVersionData)VerDoc.VersionData;
                
                NewVData.LockObject(Lock_Type.LOCK_TYPE_WRITE);
                NewVData.Version = version;
                NewVData.VersionNotes = notes;
                // Assigns the document to the new version group.
                NewVData.VersionGroup = VGroup;
                // Saves the changes.
                NewVData.Update();
                NewVData.UnlockObject();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Doc != null)
                    Doc.Dispose();
                if (VerDoc != null)
                    VerDoc.Dispose();
                OrigVData = null;
                NewVData = null;
            }
        }

 

So, if I have 4 versions, only one of them appears to be added when I view the document’s Version History in LF Client. If I double-click that version, it opens another document that has the same version, and so on endlessly.

The Version and VersionNotes that I add are never there. Why? Where did all the other versions go? I’m sure I’m making a silly mistake here.

 

I’d appreciate your help.

Thanks

1 0

Answer

SELECTED ANSWER
replied on November 18, 2015

The problem is that there are to separate versioning systems in LF9, your code is using both. There is the legacy system "Version Groups" (aka Link Groups) which links different documents together, and there is the new system which holds all version changes inside the same document. Your current code tracks versions using Version Groups and your versions should be showing up under the "Links" tab of the metadata dialog:

 

But you probably want to use the new system which would put version changes under the Versions tab. The LFVersionData class is for the old system, LFVersionControlInfo is the new system (the naming is confusing because we couldn't break compatibility with older applications). Here is how you would add a new version to an existing document:

 

LFVersionControlInfo vControlInfo = Doc.VersionControlInfo;

if (!vControlInfo.IsVersionControlled)
    vControlInfo.PutUnderVersionControl(); // Enables the new version control tracking on the document

Doc.LockObject(Lock_Type.LOCK_TYPE_WRITE);
vControlInfo.CheckOut();
Doc.Comment = ""; // Clear the old version notes
Doc.Update();

// Modify the document here. Clear out the old pages & metadata and replace them with the new version

Doc.Comment = "this is the new version notes";
Doc.Update();
vControlInfo.CheckIn(0); // Every change made to the document since CheckOut() is now combined into a new version
Doc.UnlockObject();

 

2 0

Replies

replied on November 18, 2015

 

Ah, I see.

Thank you so much!

That works great.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.