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.
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.
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(); }
I am getting the below error when trying to run the script,
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.