Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

How to create a document w/ a specific form using LotusScript

I need to be able to create a document in a notes database using a particular form named "test", set its variables to specific values, and perform a file attachment.

With the below code, I can successfully create a ducument, but I have been unable to create a document using a specific form.

Would like to create from scratch, but if I ahve to find the last one and clone it, etc. that's okay.  I just need something that works.


Note:

I am doing this from a VB app.


Sub cmdOpen_Click()


Dim db As New Domino.NotesDatabase
Dim session As New Domino.NotesSession

Dim object As Domino.NotesEmbeddedObject
Dim Body As Domino.NotesRichTextItem


' Set up error handling
On Error GoTo errhandler

' Create a Notes session
Set session = New Domino.NotesSession
 
 ' Initialize Notes Session
Call session.Initialize("thepassword")
 
 'Open the Notes Database
Set db = session.GetDatabase("", "test5.nsf")
 
If db.IsOpen = True Then
   Set doc = db.CreateDocument
    'Dim doc As New NotesDocument


     'doc.Form = "test"
     'doc.duration = 5
     'doc.JobCat = "test2"
     'doc.employee = s.UserName
     'doc.Customer = "Isn't this Cool?"
     'doc.Start = Now()
     'doc.End = Now()
     
    If (Body Is Nothing) Then Set Body = doc.CreateRichTextItem("Body")
    Set object = Body.EmbedObject(1454, "", "c:\test.txt")
    Call doc.Save(True, False)

             
 Else
        ' Put a messagebox or something here alerting user to fact that database could not bve opened.
 End If



 'Clean up memory
 Set doc = Nothing
 Set db = Nothing
 Set object = Nothing

Exit Sub
0
DLeader
Asked:
DLeader
  • 2
1 Solution
 
HemanthaKumarCommented:
The COM vary little bit, here is how your code becomes a workable one.

Dim session
Dim db
Dim object
Dim Body


' Set up error handling
'On Error GoTo errhandler

' Create a Notes session
Set session = CreateObject("Lotus.NotesSession")

' Initialize Notes Session
Call session.InitializeUsingNotesUserName("USER", "PASSWORD")
' Call session.Initialize("thepassword")



'Open the Notes Database
Set db = session.GetDatabase("", "test.nsf")

If db.IsOpen = True Then
    Set doc = db.CreateDocument
    Call doc.ReplaceItemValue("Form", "Test")
    Call doc.ReplaceItemValue("Duration", 5)
    Call doc.ReplaceItemValue("JobCat", "test2")
    Call doc.ReplaceItemValue("employee", session.UserName)
    Call doc.ReplaceItemValue("Customer", "Isn't this Cool?")
    Call doc.ReplaceItemValue("Start", Now())
    Call doc.ReplaceItemValue("End", Now())
    Set Body = doc.CreateRichTextItem("Body")
    Set object = Body.EmbedObject(1454, "", "c:\test.txt")
    Call doc.Save(True, False)
Else
       ' Put a messagebox or something here alerting user to fact that database could not bve opened.
End If



'Clean up memory
Set doc = Nothing
Set db = Nothing
Set object = Nothing

~Hemanth
0
 
DLeaderAuthor Commented:
Excellent work.  I looked all over for this answer.
0
 
HemanthaKumarCommented:
You are welcome anytime .
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now