Friday, 30 March 2018
Create New Document From UIdocument Using LotusScript
It has been some time since I wrote a new blog post. During the past period I have been very busy with a large Notes Domino Project. This concerns old school Notes development with many LotusScript Agents and Libraries. A great project. In the coming period I will publish some LotusScript Agents and Functions used in this application on my blog. In addition, I am currently working on a large XPages project. It uses modern Bootstrap and jQuery plugins. Some of these plugins will be published on my blog in the coming period.
In this blog post a small subroutine that creates a new document in a Notes application and takes over a number of data from the open UI document. The new document is then saved, the UI document is closed and the newly created document is opened as an UI document. The subroutine also includes a number of validations concerning the fields that must be filled in the UI document before the new document can be created. The subroutine can be called via an Action Button or in a Form Event. In our Notes application I added the Subroutine in a Script Library.
Sub WorkflowCreateNewDocument(doc As NotesDocument)
Dim session As NotesSession
Dim db As NotesDatabase
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim thisDoc As NotesDocument
Dim newDoc As NotesDocument
Dim NotesUIDocument As NotesUIDocument
Dim workspace As New NotesUIWorkspace
Dim Continue As Variant
Set session = New NotesSession
Set db = session.CurrentDatabase
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
EditAction = True
ws.CurrentDocument.EditMode = True
If uidoc.FieldGetText("FieldName" = 0 Then
MessageBox "FieldName is a mandatory field" ,,"Error Field FieldName."
Call uidoc.GotoField("FieldName" )
Continue = False
If uidoc.FieldGetText("FieldName2") = "" Then
MessageBox "FieldName2 is a mandatory field" ,,"Error Field FieldName2."
Call uidoc.GotoField("FieldName2" )
Continue = False
EditAction = False
If uidoc.FieldGetText("FieldName") = "0" Then
'create new document
' get document
Set thisdoc = db.GetDocumentByUNID( uidoc.Document.UniversalID )
' copy all items to new doc
Set doc = New NotesDocument( db )
Call thisdoc.CopyAllItems( doc, True )
' change some values in order to get a correct new document
.FieldName1 = doc.UniversalID
.Form = "FormName"
.FieldName2 = "TextValue"
.FieldName3 = Today()
.FieldName4 = Now()
.FieldName5 = ""
' save new document
Call doc.Save(True, False)
' open new document
Set notesUIDocument = workspace.EditDocument( False , doc )
' close current document
uidoc.Close( True )
A small but very useful subroutine to quickly create a new document with a number of data from the opened UI document.
In my next blog posts I will publish some LotusScript Functions that we have recently implemented within our Notes application.
Geplaatst door Johnny Oldenburger op Friday, March 30, 2018