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!
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.