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

Question

Question

Add a new document version in SDK Script

asked on March 27, 2019

Hi LF Community, 

I want to know if SDK Script allows to create a new version of an existing document and what's the adequate function to do this.

 

 

1 0

Answer

SELECTED ANSWER
replied on March 27, 2019

Using the .NET SDK (Laserfiche.RepositoryAccess), create a new version like this:

 

using (DocumentInfo newDoc = Document.GetDocumentInfo(docId, session))
{
    newDoc.LockPersistently("This is my checkout comment");

    if (!newDoc.IsUnderVersionControl)
        newDoc.PutUnderVersionControl();

    // Check out the document
    newDoc.CheckOut();

    // Make your changes here
    // ...

    newDoc.Comment = "This is my new version comment";
    newDoc.Save();
    newDoc.CheckIn();
    newDoc.PersistentLock.Delete();
    newDoc.PersistentLock.Save();
}

 

3 0
replied on August 6

I am getting the below error when trying to run the script,

image (3).png
image (3).png (107.51 KB)
0 0
replied on August 6

In a Workflow SDKScript activity, there is already a reference to the entry and the session, so you do not need to create those.  The entry that the SDK Script is set to run on is referenced as BoundEntryInfo and is an EntryInfo object. Since you want to work with a DocumentInfo object, you first check that the BoundEntryInfo object is a Document and then you create a new DocumentInfo object from the BoundEntryInfo object.

        protected override void Execute()
        {
            // Write your code here. The BoundEntryInfo property will access the entry, RASession will get the Repository Access session
            if (BoundEntryInfo.EntryType == EntryType.Document){
                using (DocumentInfo newDoc = (DocumentInfo)BoundEntryInfo)
                {
                    newDoc.LockPersistently("This is my checkout comment");
                
                    if (!newDoc.IsUnderVersionControl)
                        newDoc.PutUnderVersionControl();
                
                    // Check out the document
                    newDoc.CheckOut();
                
                    // Make your changes here
                    // ...
                
                    newDoc.Comment = "This is my new version comment";
                    newDoc.Save();
                    newDoc.CheckIn();
                    newDoc.PersistentLock.Delete();
                    newDoc.PersistentLock.Save();
                }
            }
        }

Note that I did not test this code, but it should be close to what you are looking for.

1 0

Replies

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

Sign in to reply to this post.