LotusScript help needed

I am trying to create a script in the querysave event of a form that will send an email to myself whenever a new document is created using the form. I am getting an error that reads “Object variable not set”. Also, I would like to include a doclink to the document being created in the email that is being sent. Any help would be greatly appreciated.

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim db As NotesDatabase

Set uidoc = ws.CurrentDocument

If uidoc.IsNewDoc Then

REM {Send Email to IT}

	Dim Session As New NotesSession	

	Set doc = db.createdocument

	doc.form = "Memo"

	doc.Sendto = "myemail@mycompany.com"

	doc.subject = session.commonusername & " has created a new Help Database entry"

	doc.send False

End If

Subject: Just forgot to set db…

Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim db As NotesDatabase

Set uidoc = ws.CurrentDocument

If uidoc.IsNewDoc Then

REM {Send Email to IT}

	Dim Session As New NotesSession	

	Set db = Session.CurrentDatabase

	Set doc = db.createdocument

	doc.form = "Memo"

	doc.Sendto = "myemail@mycompany.com"

	doc.subject = session.commonusername & " has created a new Help Database entry"

	doc.send False

End If

Subject: RE: Just forgot to set db…

Thanks to both of you. After I set db the email was created. I am still unsure of how to incoroprate additional code in the current script that would include a doclink.

Thanks again in advance

Subject: RE: Just forgot to set db…

Do you understand lotus script? And how to call functions and sub routines? I gave you all the code for generating the emails with a link.

Subject: RE: Just forgot to set db…

I was hoping to add code to MY script that would allow me to create a doclink. I really appreciate your code example but I’m not sure how to incorporate your code into mine.

Subject: You have got to at least try, if you expect to get some help here.

I’ll give you this one.Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim cdoc As NotesDocument

Dim rt As NotesRichTextItem

Dim db As NotesDatabase

Set uidoc = ws.CurrentDocument

Set cdoc = uidoc.Document

If uidoc.IsNewDoc Then

REM {Send Email to IT}

	Dim Session As New NotesSession	

	Set db = Session.CurrentDatabase

	Set doc = db.createdocument

	doc.form = "Memo"

	doc.Sendto = "myemail@mycompany.com"

	doc.subject = session.commonusername & " has created a new Help Database entry"

	Set rt = doc.CreateRichTextItem("Body")

	Call rt.AppendText("Follow this link to the document in the Help Database -->")

	Call cdoc.Save(True, False)

	Call rt.AppendDocLink(cdoc, "Follow this")

	Call rt.Update

	doc.send False

End If

Subject: RE: You have got to at least try, if you expect to get some help here.

Hi Bill,

That’s exactly what I was doing (playing around with the appenddoclink method) but did not have the correct logic nor other related commands that you shared. For instance, I was trying to use a “Body” field but didnt know that you had to create it by using CreateRichTextItem…I know that this is probably basic stuff for you power scripters but the average guy like myself who is trying to piece this all together, it doesnt come as naturally as it does to you <>

I’m trying to learn more by reading the help file and asking questions here on the forum.

Thanks for the help

Subject: No problem. Looking at the examples in the help is how most of us learned this stuff.

Subject: RE: Just forgot to set db…

OK. I thought I was actually making it easier for you.

What you need to do is create a rich text item, for the body field. use appendText to put your text description and then you will need to append the document as a link. See below:

	Set tmpRTItem = New NotesRichTextItem(MailDoc, "Body")

	tmpRTItem.AppendText ("Name: " + currentdoc.EmpName(0)   +" - Term Date: " + Cstr(currentdoc.LWDate(0)))

	tmpRTItem.AppendText(Chr$(13) & Chr$(13) )

	If Not(docTicket Is Nothing) Then

		Call tmprtitem.AppendDocLink( docTicket, "DocLink to User Profile Request","Link to User Profile Request") 			

	End If

	Call maildoc.Send( False )

Subject: RE: Just forgot to set db…

I’ll give it a try. Thanks for all of your help and patience.

Subject: LotusScript help needed…

You didn’t set db

Missing set db=session.CurrentDatabase

You could have found this if you turned on the debugger.

Also, look at the notesdocument

Probably want to add this to your postsave event. You won’t have the documents unid to create the doclink for.

Here is a function that I use to send out email messages. I think you can figure out what the parameters are and what should be put in each. If not, let me know:

Public Sub SendMailMemo (SendTo As Variant, CCTo As Variant, BCCTo As Variant, SentBy As String, Subject As String, MemoText As String, DocLinkUNID As String, DocLinkComment As String)

 '   PARAMETERS

 '   SendTo, CCTo, BCCTo are the addressee fields, string or array of strings corresponding to Names

 '   SentBy is the sender of the document, string

 '   Subject is the subject of the message, string

 '   MemoText is the text portion of the body of the message, string

 '   DocLinkUNID is the universal id of the document, string

 '   DocLinkComment is the context-sensitive comment related to the doclink, string

 '   NOTE:  If there is no corresponding DocLink for the message, pass an empty string for both the universal id and the comment



Dim tmpSession As New NotesSession

Dim tmpMailDoc As New NotesDocument(tmpSession.CurrentDatabase)

Dim tmpRTItem As NotesRichTextItem

Dim tmpicon As notesitem

 'Set the form

tmpMailDoc.Form = "EmailMemo"



 'Address the message     

tmpMailDoc.SendTo = SendTo

tmpMailDoc.CopyTo =  CCTo

tmpMailDoc.BlindCopyto = BCCTo

tmpMailDoc.SentBy = SentBy     

tmpMailDoc.Subject = Subject

Set tmpicon=tmpMailDoc.Replaceitemvalue("_ViewIcon",121)



 'Create the body of the text, including DocLink, if applicable

Set tmpRTItem = New NotesRichTextItem(tmpMailDoc, "Body")

tmpRTItem.AppendText MemoText



If DocLinkUNID > "" Then

	tmpRTItem.AppendText Chr$(13) & Chr$(13) & Chr$(13)

	tmpRTItem.AppendDocLink tmpSession.CurrentDatabase.GetDocumentByUNID(DocLinkUNID), DocLinkComment, DocLinkComment

End If



 'Send the message

tmpMailDoc.Send True

End Sub