Reputation: 195
I have a document and a copy of the document. I want to create a document lock for the document using LotusScript.
I have separately put the current document inside Computer view and copy document inside Draft view. Below here the action to create a copy.
Create copy
Sub Click(Source As Button)
Dim ns As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim newdoc As NotesDocument
Dim dc As NotesDocumentCollection
Set db= ns.CurrentDatabase
Set dc= db.UnprocessedDocuments
If dc.Count<>1 Then
Messagebox "No or too many documents selected"
Exit Sub
End If
Set doc= dc.GetFirstDocument
Set newdoc= doc.CopyToDatabase(db)
Call newdoc.ReplaceItemValue("PStatus", "Draft")
Call newdoc.Save(True, False)
End Sub
Save Button
Sub Click(Source As Button)
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim view As NotesView
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set view = db.GetView("Draft")
Set doc = view.GetDocumentByKey("Draft", True)
vpswd = Inputbox$("Pls input code to save :")
If vpswd = "o" Then
uidoc.EditMode = True
Set doc = uidoc.Document
Set doc = view.GetFirstDocument
If doc.PStatus(0) = "Draft" Then
Set newdoc= doc.CopyToDatabase(db)
Call newdoc.ReplaceItemValue("PStatus", "Active")
Call newdoc.Save(True, False)
End If
Call uidoc.FieldSetText("SaveOptions" , "1")
Call uidoc.Save
Call uidoc.Close
End If
End Sub
How can I lock a current document every time I create a copy of the document? E.g current document will lock when the copy document created.
Another question is, for copy document, after I saved, I want to replace the current document as a copy document and a copy document will be a live document. While the current document will not be deleted from the database but deleted from Computer view and displayed in the "Archived" view.
And inside Draft view, copy document will be deleted from view. Any help will be appreciated. Thanks!
Upvotes: 0
Views: 381
Reputation: 5
I have done something similar. When a new version, as I call it, is created, it is the "draft" document. The previous document is an "approved" document. User get to see only the approved until the new version is approved, then the older approved document is archived out of the db. If you want all versions to stay in the db, but only the newer document brought up, you could use what I call a HistoryID field. Basically I have a field on every document that has up to three values in it:
TheUNID
ParentUNID:TheUNID:Parent
TheUNID:ChildUNID:Child
The "theUNID" field is computed when composed so it never changes. If a new version or draft is created, the HistoryID would now have two values:
TheUNID
TheUNID:ChildUNID:Parent
This let's you know you now have a new draft and the document you are on is actually a parent. The "ChildUNID" is actually "theUNID" of the draft document you just created.
On the child document or the new draft document you put in the HistoryID:
TheUNID ParentUNID:TheUNID:Parent
This way your draft knows who it's parent is.
In your code in your db, you just have any document that gets opened check the HistoryID field first. If there is a child, you take the user to the child. It doesn't matter what parent gets opened or how far back the generations go, your code continues to iterate through the HistoryID until the current child document is found that doesn't have a parent. Sound good?
Let me know if you need clarification.
Upvotes: 0
Reputation: 2359
Locking a document should be implicit. Make sure that you use the Status field in all documents. E.g. when you create the copy, set the status of the copied document to "Copied" and the nw documof nt to "Draft". You have to cover all different status changes. Best is also to add one field that contains a unique document Id that can never be changed. Maybe also add a version number.
Examples of statuses:
It might help to create a STD, a State Transition Diagram.
Upvotes: 1