Yet another "Type mismatch" in Lotusscript

Hi,

I’m trying to go through documents I have in a View called CTCDone and send out and e-mail to persons who have had their mail converted from our old POP3 server to Notes and along the way notify key personnel who need to know such a conversion has taken place. If the document is in this view and the field EmailNotificationOfCompletion = N then the document should be processed.

However, as I walk through the code with the Script Debugger I get a “Type Mismatch” Error. I have put an arrow by the line where the code bombs out. Can someone take a look and maybe give me some recommendations?

Sub Initialize

Dim s As New notessession

Dim db As notesdatabase

Dim doc As notesdocument

Dim maildoc As notesdocument

Dim rtitem As notesrichtextitem

Dim copytoPeople(0 To 1) As String

Dim view As NotesView





servername = s.UserName

Set db = s.CurrentDatabase

'Set doc = s.DocumentContext



Set view = db.getview("CTCDone")

Set doc = view.getfirstdocument



Do While Not doc Is Nothing

	

	If doc.EmailNotificationOfCompletion = N Then  (<-- Type mistach occurs here)

		

		doc.Status = "Done" 

		

		Set maildoc = db.CreateDocument

		copytoPeople(0) = "person@mail.edu"

	        copytoPeople(1) =   "person@mail.edu"

	

		maildoc.form = "Memo"

		'maildoc.SendTo = doc.Email(0)

		maildoc.SendTo =   "person@mail.edu"

		maildoc.CopyTo = copytoPeople

		maildoc.subject = "Migration from Mail1 to Notes mail complete"

		

		Set rtitem = New NotesRichTextItem(maildoc,"Body")

		Call rtitem.appendtext("If you are an iNotes user then you migration is complete.  If you have a GUI Notes client then follow the below")

		Call rtitem.addnewline(1)

		Call rtitem.appendtext("Your Mail1/Mail2 email has been migrated to MCVH.  To finish migrating your address book, please follow the instructions below:")

		Call rtitem.addnewline(2)

		Call rtitem.AppendText("1. Open your Mail")

		Call rtitem.addnewline(1)

		Call rtitem.AppendText("2. Select Actions - Synchronize Address Book from the actions menu at the top of the screen.")

		Call rtitem.appendtext("Your Mail1/Mail2 email has been migrated to M.")

		Call rtitem.AddNewline(2)

		Call rtitem.AppendText("A request has been submitted to remove your Mail1/Mail2 email account.")

		Call rtitem.AddNewline(2)

		

		Call rtitem.AppendText("Your M email address(" +  "person@mail.edu" + ") will be redirected to " +  "person@mail.edu" + ".")

		Call rtitem.AddNewline(2)

		Call rtitem.AppendText("Lotus Support Team")

		Call rtitem.addnewline(1)

		Call rtitem.AppendText("Contact the Help Desk with questions at 555-1212")

		Call maildoc.Send(False)

	End If

	doc.EmailNotificationOfCompletion = Y

	

	Set doc = view.getnextdocument(doc)	

Loop



Exit Sub

End Sub

Subject: Yet another “Type mismatch” in Lotusscript

If doc.EmailNotificationOfCompletion(0) = “N” Then

You’ll need to refer to the first element of the field, hence the “(0)”, and

unless N is some sort of unmentioned variable, I suspect that it’s text.

Subject: RE: Yet another “Type mismatch” in Lotusscript

Collin-Thanks for the quick response. You were correct it was a text field and adding the (0) worked. The agent ran fine except for one thing where I’m setting

doc.EmailNotificationOfCompletion = “Y” at the end is not resetting the EmailNotificationOfCompletion field to “Y”. Any possible thoughts on this. Sorry but I’m an Admin who struggles with Lotusscript.

Thx

Subject: RE: Yet another “Type mismatch” in Lotusscript

You got to save it as you are updating that field of doc to “Y”.

Hence add this line --------> Call doc.Save(False, True)

after —> doc.EmailNotificationOfCompletion = “Y”

Subject: RE: Yet another “Type mismatch” in Lotusscript

Yup it worked. Thanks Narasimhan! For those interested this is the correct code.

Sub Initialize

Dim s As New notessession

Dim db As notesdatabase

Dim doc As notesdocument

Dim maildoc As notesdocument

Dim rtitem As notesrichtextitem

Dim copytoPeople(0 To 1) As String

Dim view As NotesView

servername = s.UserName

Set db = s.CurrentDatabase

'Set doc = s.DocumentContext

Set view = db.getview(“CTCDone”)

Set doc = view.getfirstdocument

Do While Not doc Is Nothing

If doc.EmailNotificationOfCompletion(0) = "N"Then

doc.Status = “Done”

Set maildoc = db.CreateDocument

copytoPeople(0) = “person@mail.edu”

copytoPeople(1) = “person@mail.edu”

maildoc.form = “Memo”

'maildoc.SendTo = doc.Email(0)

maildoc.SendTo = “person@mail.edu”

maildoc.CopyTo = copytoPeople

maildoc.subject = “Migration from Mail1 to Notes mail complete”

Set rtitem = New NotesRichTextItem(maildoc,“Body”)

Call rtitem.appendtext(“If you are an iNotes user then you migration is complete. If you have a GUI Notes client then follow the below”)

Call rtitem.addnewline(1)

Call rtitem.appendtext(“Your Mail1/Mail2 email has been migrated to MCVH. To finish migrating your address book, please follow the instructions below:”)

Call rtitem.addnewline(2)

Call rtitem.AppendText(“1. Open your Mail”)

Call rtitem.addnewline(1)

Call rtitem.AppendText(“2. Select Actions - Synchronize Address Book from the actions menu at the top of the screen.”)

Call rtitem.appendtext(“Your Mail1/Mail2 email has been migrated to M.”)

Call rtitem.AddNewline(2)

Call rtitem.AppendText(“A request has been submitted to remove your Mail1/Mail2 email account.”)

Call rtitem.AddNewline(2)

Call rtitem.AppendText(“Your M email address(” + “person@mail.edu” + ") will be redirected to " + “person@mail.edu” + “.”)

Call rtitem.AddNewline(2)

Call rtitem.AppendText(“Lotus Support Team”)

Call rtitem.addnewline(1)

Call rtitem.AppendText(“Contact the Help Desk with questions at 555-1212”)

Call maildoc.Send(False)

End If

Call doc.Save(False,True)

doc.EmailNotificationOfCompletion = Y

Set doc = view.getnextdocument(doc)

Loop

Exit Sub

End Sub

Subject: RE: Yet another “Type mismatch” in Lotusscript

You can also remove that string array by doing something like this:

dim item as notesitem

set item = doc.replaceitemvalue(“Copyto”,“somename”)

call item.appendtotextlist(“anothername”)

Then you can re-use item wherever you need a handle to a notesitem, thus removing the string array from the picture. One less variable.

Subject: RE: Yet another “Type mismatch” in Lotusscript

Are you sure its working?

Call doc.Save(False,True)

doc.EmailNotificationOfCompletion = Y

You are saving the document and then setting a field. It needs to be the other way around and also enclose the Y in quotes.

Subject: RE: Yet another “Type mismatch” in Lotusscript

Man! You did not follow my posting properly. If by any chance, you think it is not working, then see my earlier posting again.

Subject: RE: Yet another “Type mismatch” in Lotusscript

Better still, don’t use the extended syntax at all as it makes for hard-to-find bugs. Instead of

If doc.EmailNotificationOfCompletion(0) = “N” Then

use

If doc.getfirstitem(“EmailNotificationOfCompletion”).text = “N” Then

or

If doc.getfirstitem(“EmailNotificationOfCompletion”).values(0) = “N” Then

The problem with the extended syntax is that if you misspell the fieldname - EmailNotificationOfConpletion - the script will treat that as a sort of undeclared variable whose value never equals “N”. With the explicit syntax you would get an Object Variable Not Set (becuase there’s no item named EmailNotificationOfConpletion), so you would find the bug immediately.