newuser
asked on
Lotus Notes 8.5 - Check for unread messages/documents
Hi
I am a newbie to Lotus Notes but have been given the task of retreving unread documents from Lotus Domino server. I have Domino Server 8.5 installed in one machine and the client on my machine. Iam writing a VB program to create a session and get into the Inbox folder. I want to get the documents that are not readfrom Inbox. However, I am not able to do so!!
I see from the IBM info center, that there is a method on the NotesDatabase class called getAllUnreadDocuments that satisifes my criteria. However when I use it in the program, I get the error "Property or method not supported". Does it mean that the Lotus Class that Iam referring to is wrong? Or is there any other way to access unread documents?
Any help would be greatly appreciated.
Regards
I am a newbie to Lotus Notes but have been given the task of retreving unread documents from Lotus Domino server. I have Domino Server 8.5 installed in one machine and the client on my machine. Iam writing a VB program to create a session and get into the Inbox folder. I want to get the documents that are not readfrom Inbox. However, I am not able to do so!!
I see from the IBM info center, that there is a method on the NotesDatabase class called getAllUnreadDocuments that satisifes my criteria. However when I use it in the program, I get the error "Property or method not supported". Does it mean that the Lotus Class that Iam referring to is wrong? Or is there any other way to access unread documents?
Any help would be greatly appreciated.
Regards
Dim session As Domino.NotesSession
Dim Maildb As Domino.NotesDatabase
Dim MailDoc As Domino.NotesDocument
Dim dir As Domino.NotesDbDirectory
Set session = New Domino.NotesSession
Call session.Initialize(<password>)
Set dir = session.GetDbDirectory(<machine name>)
Set Maildb = dir.OpenDatabase(<nsf file>)
set Inboxfolder = Maildb.GetView("$Inbox")
Dim totalmsgscount As Integer
totalmsgscount = Inboxfolder.AllEntries.Count
Dim unreadmsgcollxn As domino.NotesNoteCollection
Set unreadmsgcollxn = Maildb.db.GetAllUnreadDocuments() 'I get the error as "Object does not support this property or method"
ASKER
Thanks for noting the error SysExpert. Am so sorry, it was a mistake on my part while copying and pasting the code from my VB project to the Experts-Exchange site and modifying the same. Please treat the line
Maildb.db.GetAllUnreadDocu ments()
AS
Maildb.GetAllUnreadDocumen ts()0
Maildb.db.GetAllUnreadDocu
AS
Maildb.GetAllUnreadDocumen
ASKER
Apologies again for the typo in the code snippet. Please treat it as follows:
Maildb.db.GetAllUnreadDocu ments()
AS
Maildb.GetAllUnreadDocumen ts()
Maildb.db.GetAllUnreadDocu
AS
Maildb.GetAllUnreadDocumen
maybe it should be
Inboxfolder.GetAllUnreadDo cuments()
Inboxfolder.GetAllUnreadDo
ASKER
Thanks for the info SysExpert. I checked in the NotesView class and found one entry called GetAllUnreadEntries() that retrieves all the unread documents present in the view. I tried using the same but ended with the same error "Object doesnt support the property or method".
More information from my side:
I am using trial downloads of Lotus Domino Server 8.5 and Lotus Notes client 8.5
I am referencing "Lotus Domino Objects" and "Lotus Notes Automation Classes" in my VB project.
More information from my side:
I am using trial downloads of Lotus Domino Server 8.5 and Lotus Notes client 8.5
I am referencing "Lotus Domino Objects" and "Lotus Notes Automation Classes" in my VB project.
I would add error checking and logging at each command to be sure that it is doing, what you think it is.
Could it be that the object libraries you use are from an older Notes release?
Couple of remarks:
1. Dim unreadmsgcollxn As domino.NotesNoteCollection - when you get the unread entries from a view/folder then actually the type must be Domino.NotesViewEntryColle ction.
notesdatabase.GetAllUnread Documents( ) returns NotesNoteCollection
2. When you are typing the method name: Inboxfolder.GetAllUnreadDo cuments() in VB editor, can you actually see the method name in object propeties? If you are using Visual Studio, then type-ahead must show you the list of existing properties and methods. If it is not in list, then the method is not supported in COM.
I tried it, using Lotus Domino Objects COM version 1.2.0 and did not see those methods in list.
1. Dim unreadmsgcollxn As domino.NotesNoteCollection
notesdatabase.GetAllUnread
2. When you are typing the method name: Inboxfolder.GetAllUnreadDo
I tried it, using Lotus Domino Objects COM version 1.2.0 and did not see those methods in list.
Seems those functions are NOT implemented in COM, as stated in document http://www.ipi.org/help/help8_designer.nsf/f4b82fbb75e942a6852566ac0037f284/434a089c9d8af96b8525731b0049e5c1?OpenDocument.
Function view.GetAllUnreadDocuments () is not mentioned at all, db.GetAllUnreadDocuments() is specified as not supported.
Maybe you can modify and use the functions from class, described in http://www.nsftools.com/tips/NotesTips.htm#unreaddocs .
Function view.GetAllUnreadDocuments
Maybe you can modify and use the functions from class, described in http://www.nsftools.com/tips/NotesTips.htm#unreaddocs .
ASKER
Hello Olaraak
Thanks for the information. I was also thinking of the same! However, the URL http://www.ipi.org/help/help8_designer.nsf/f4b82fbb75e942a6852566ac0037f284/434a089c9d8af96b8525731b0049e5c1?OpenDocument details about Lotus 8.0. I am actually using 8.5. Is there any documentation for 8.5 that describes the differences in COM?
Thanks for the information. I was also thinking of the same! However, the URL http://www.ipi.org/help/help8_designer.nsf/f4b82fbb75e942a6852566ac0037f284/434a089c9d8af96b8525731b0049e5c1?OpenDocument details about Lotus 8.0. I am actually using 8.5. Is there any documentation for 8.5 that describes the differences in COM?
ASKER
yes sief bosman..it does look identical!! Looks like i will have to take the long way around in storing the message ids of each of the message and if that id is not present in the DB, then read the message!!
However, I can foresee another potential problem here! Even if I read the message, there seems to be no flag that I can set to let Lotus Domino/Notes that this message has been read!!
However, I can foresee another potential problem here! Even if I read the message, there seems to be no flag that I can set to let Lotus Domino/Notes that this message has been read!!
It seems possible to call GetAllUnreadDocuments from a Java application or class. Is Java an option for you?
ASKER
Hello Sief Bosman..thanks for the information!! Java is not feasible as we are planning to use COM components for our application.
It doesn't seem to be impossible to call Java from VB...
http://visualbasic.ittoolbox.com/groups/technical-functional/visualbasic-l/call-java-objects-from-vb-321298
http://stackoverflow.com/questions/152967/can-you-use-java-libraries-in-a-vb-net-program
http://visualbasic.ittoolbox.com/groups/technical-functional/visualbasic-l/call-java-objects-from-vb-321298
http://stackoverflow.com/questions/152967/can-you-use-java-libraries-in-a-vb-net-program
ASKER
thanks for the info Sief Bosman. Will try this out. However, if you find anything else please let me know.
Regards
Regards
ASKER
Whilst still tryin to find a way to get the Unread documents, I have hit upon 2 more issues
- If I get an unread document, how can i set the same to READ? Is there a flag to be set in COM?
- If I need to reply to the mail, I use CreateReplyMessage method of Notesdocument class. But it doesnt seem to append the text!! Please find the code snippet
- If I get an unread document, how can i set the same to READ? Is there a flag to be set in COM?
- If I need to reply to the mail, I use CreateReplyMessage method of Notesdocument class. But it doesnt seem to append the text!! Please find the code snippet
Dim inboxfolder As Domino.NotesView
Dim doc As Domino.NotesDocument
Dim MailDoc As Domino.NotesDocument
Set inboxfolder = Maildb.GetView("$Inbox")
Set MailDoc = inboxfolder.GetFirstDocument
Set doc = MailDoc.CreateReplyMessage(False)
Call MailDoc.CopyAllItems(doc, True)
Call doc.AppendItemValue("Body", "This is a reply to the mail - NS ")
doc.SaveMessageOnSend = True
doc.Send False
doc.PutInFolder ("$Sent")
Dim lb As Boolean
lb = doc.Save(True, True)
As to the READ flag, there are the methods NotesDocumentCollection.Ma rkAllRead and NotesDocument.MarkRead. Whether they are available in COM I couldn't tell.
And your code is not quite right:
Set MailDoc = inboxfolder.GetFirstDocume nt
Set doc = MailDoc.CreateReplyMessage (False)
These lines created a reply-message, with everything set as it should except for the Subject-field.
But with
Call MailDoc.CopyAllItems(doc, True)
you practically undo the CreateReplyMessage: all items are overwritten.
Then, the next line
Call doc.AppendItemValue("Body" , "This is a reply to the mail - NS ")
That's impossible, because that method is used for multi-value text-items, but in 99.9% of all messages, the Body-item is a rich-text item and has to be handled accordingly. You have to Get the Body-item, and use APpendText to add text at the end.
And your code is not quite right:
Set MailDoc = inboxfolder.GetFirstDocume
Set doc = MailDoc.CreateReplyMessage
These lines created a reply-message, with everything set as it should except for the Subject-field.
But with
Call MailDoc.CopyAllItems(doc, True)
you practically undo the CreateReplyMessage: all items are overwritten.
Then, the next line
Call doc.AppendItemValue("Body"
That's impossible, because that method is used for multi-value text-items, but in 99.9% of all messages, the Body-item is a rich-text item and has to be handled accordingly. You have to Get the Body-item, and use APpendText to add text at the end.
ASKER
Hello Stef
Taking your suggestions into consideration, I applied the same in my code. The reply kinda worked!! Please see the attached snippet and also the Lotus Notes mail that got generated from the code.
As seen in the attached file, the appended text along with the original is coming in the below part of the mail (i.e. the parent mail) while the Reply mail body is blank. Any suggestions as to what I am doing wrong in the code? (Also, I need to just add the text to the reply mail and not append it to the parent mail)
Thanks in advance
Regards
Taking your suggestions into consideration, I applied the same in my code. The reply kinda worked!! Please see the attached snippet and also the Lotus Notes mail that got generated from the code.
As seen in the attached file, the appended text along with the original is coming in the below part of the mail (i.e. the parent mail) while the Reply mail body is blank. Any suggestions as to what I am doing wrong in the code? (Also, I need to just add the text to the reply mail and not append it to the parent mail)
Thanks in advance
Regards
Dim inboxfolder As Domino.NotesView
Set inboxfolder = Maildb.GetView("$Inbox")
Set MailDoc = inboxfolder.GetFirstDocument
Dim doc As Domino.NotesDocument
Set doc = MailDoc.CreateReplyMessage(False)
Call doc.ReplaceItemValue("Form", "Reply")
Dim strbody As String
Dim ritem As Domino.NotesRichTextItem
Set ritem = MailDoc.GetFirstItem("Body")
ritem.AppendText ("This is a reply to the mail242434 - NS")
ritem.AddNewLine (1)
Call doc.CopyItem(ritem, "Body")
Call doc.ReplaceItemValue("Subject", "Re: " & MailDoc.GetFirstItem("Subject").Text)
doc.SaveMessageOnSend = True
Call doc.Send(False, "system/sone")
doc.PutInFolder ("$Sent")
Dim lb As Boolean
lb = doc.Save(True, True)
ReplyMail.JPG
Progress! Love it :-)
Do you really have to copy over the rich text item? According to this link:
http://www-01.ibm.com/support/docview.wss?uid=swg21192171
CreateReplyMessage does a lot more than you think. There should already be a Body in the reply message. Apparently, you can get it and start appending text at the right place.
Change your code into:
Set ritem = doc.GetFirstItem("Body")
ritem.AppendText ("This is a reply to the mail242434 - NS")
ritem.AddNewLine (1)
' Call doc.CopyItem(ritem, "Body") ' or remove this line
and test again.
Do you really have to copy over the rich text item? According to this link:
http://www-01.ibm.com/support/docview.wss?uid=swg21192171
CreateReplyMessage does a lot more than you think. There should already be a Body in the reply message. Apparently, you can get it and start appending text at the right place.
Change your code into:
Set ritem = doc.GetFirstItem("Body")
ritem.AppendText ("This is a reply to the mail242434 - NS")
ritem.AddNewLine (1)
' Call doc.CopyItem(ritem, "Body") ' or remove this line
and test again.
ASKER
thanks for the input Sief.
However it is the same result!! Please find the code snippet and the mail that was received in the attachment
However it is the same result!! Please find the code snippet and the mail that was received in the attachment
Dim session As Domino.NotesSession
Dim Maildb As Domino.NotesDatabase
Dim UserName As String
Dim MailDoc As Domino.NotesDocument
Dim dir As Domino.NotesDbDirectory
Dim doccoll As Domino.NotesDocumentCollection
Set session = New Domino.NotesSession
Call session.Initialize(<password>)
UserName = session.UserName
Set dir = session.GetDbDirectory(<directory>)
Set Maildb = dir.OpenDatabase(<nsf file>)
Dim inboxfolder As Domino.NotesView
Set inboxfolder = Maildb.GetView("$Inbox")
Set MailDoc = inboxfolder.GetFirstDocument
Dim doc As Domino.NotesDocument
Dim ritem As Domino.NotesRichTextItem
Set doc = MailDoc.CreateReplyMessage(False)
Set ritem = doc.GetFirstItem("Body")
Call ritem.AppendText("This is a reply to the mail242434 - NS")
Call doc.ReplaceItemValue("Form", "Reply")
Call doc.ReplaceItemValue("Subject", "Re: " & MailDoc.GetFirstItem("Subject").Text)
doc.SaveMessageOnSend = True
Call doc.Send(False, "system/sone")
doc.PutInFolder ("$Sent")
Dim lb As Boolean
lb = doc.Save(True, True)
ReplyMail2.JPG
Then add, after line 24
Call body.BeginInsert(rtitem)
Call body.BeginInsert(rtitem)
ASKER
I believe I cannot use it as is! I looked at certain examples and found that they require NotesRichTextNavigator objects as well !! Please correct me if I am wrong
ASKER
Well..some progress at least!! I scanned thro' the IBM infocenter and found some code that was useful. I have changed it accordingly and have attached the code snippet and also the Reply mail that gets generated from it. Please do have a look at the same and guide me on where Iam coding it wrong.
Tried using RTELEM_TYPE_TEXTPARAGRAPH and RTELEM_TYPE_TEXTRUN to get to the beginning of the mail. didnt work!! Removed the line rtnav.FindFirstElement(RTE LEM_TYPE_T EXTPARAGRA PH) and tried to use just Call body.BeginInsert(rtnav), got an error!
Thanks in advance
Tried using RTELEM_TYPE_TEXTPARAGRAPH and RTELEM_TYPE_TEXTRUN to get to the beginning of the mail. didnt work!! Removed the line rtnav.FindFirstElement(RTE
Thanks in advance
Dim session As Domino.NotesSession
Dim Maildb As Domino.NotesDatabase
Dim MailDoc As Domino.NotesDocument
Dim dir As Domino.NotesDbDirectory
Dim doc As Domino.NotesDocument
Dim body As Domino.NotesRichTextItem
Dim rtnav As Domino.NotesRichTextNavigator
Dim inboxfolder As Domino.NotesView
Dim firstdoc As Domino.NotesDocument
Set session = New Domino.NotesSession
Call session.Initialize(<password>)
Set dir = session.GetDbDirectory(<directory>)
Set db = dir.OpenDatabase(<NSF File>)
Set inboxfolder = db.GetView("$Inbox")
Set firstdoc = inboxfolder.GetFirstDocument
Set doc = firstdoc.CreateReplyMessage(False)
Set body = doc.GetFirstItem("Body")
Set rtnav = body.CreateNavigator
Call rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH)
Call body.BeginInsert(rtnav)
Call body.AppendText("Testing from command 4")
Call body.AddNewLine(1)
Call body.EndInsert
Call doc.ReplaceItemValue("Form", "Reply")
Call doc.ReplaceItemValue("Subject", "Re: " & firstdoc.GetFirstItem("Subject").Text)
doc.SaveMessageOnSend = True
Call doc.Send(False)
Call doc.PutInFolder("$Sent")
Call doc.Save(True, False, True)
Set firstdoc = Nothing
Set inboxfolder = Nothing
Set rtnav = Nothing
Set body = Nothing
Set doc = Nothing
Set dir = Nothing
Set Maildb = Nothing
Set session = Nothing
ReplyMail3.JPG
Ah, good! Sorry I didn't mention that you have to create a navigator-object.
What I'm afraid of is that VB doesn't know the constant RTELEM_TYPE_TEXTPARAGRAPH. Try using the constant 4 instead.
What I'm afraid of is that VB doesn't know the constant RTELEM_TYPE_TEXTPARAGRAPH.
ASKER
HEllo Sief
Tried with constant 4. Its the same result yet again!! :(
Tried with constant 4. Its the same result yet again!! :(
ASKER
or is it that I am missng setting some property? As you can see, the original mail's history says that the mail is forwarded, while the look and feel of a proper Reply mail in Lotus Notes is different.
Just one question: why do you change the Form to "Reply" ?? Can you try with "Memo" ?
And can you add some lines after you add the text?
And can you add some lines after you add the text?
ASKER
Changed the Form to Memo and added a few more text and around 6 new lines..Please find the snapshot of the Reply Mail
ReplyMail4.JPG
ReplyMail4.JPG
Hmmm... Maybe the Reply-form wasn't so bad after all...
What I think is that the text is inserted in a table cell. Can you try with different calls to FindFirst, one per type of element, so that you know which element comes first?
What I think is that the text is inserted in a table cell. Can you try with different calls to FindFirst, one per type of element, so that you know which element comes first?
If you want to delve into the murky depths of a Notes database:
http://www-10.lotus.com/ldd/sandbox.nsf/ByDateNJ/2791869f4e1d3fa385256f2c00432973?OpenDocument
http://www-10.lotus.com/ldd/sandbox.nsf/ByDateNJ/2791869f4e1d3fa385256f2c00432973?OpenDocument
ASKER
Hello Sjef,
Tried all the permutations and combinations!! But nothing worked!!
RTELEM_TYPE_TABLE (1) - Lotus Mail client hung for this mail. I had to terminate the process and restart the client again
RTELEM_TYPE_TEXTPARAGRAPH (4) - You have seen the result already
RTELEM_TYPE_TEXTRUN (3) - same as paragraph
RTELEM_TYPE_TABLECELL (7) - overwrites on the mail icon of the original mail
RTELEM_TYPE_DOCLINK (5) - VB error while executing
RTELEM_TYPE_FILEATTACHMENT (8) - VB error while executing
RTELEM_TYPE_OLE (9) - VB error while executing
RTELEM_TYPE_SECTION (6) - VB error while executing
Tried all the permutations and combinations!! But nothing worked!!
RTELEM_TYPE_TABLE (1) - Lotus Mail client hung for this mail. I had to terminate the process and restart the client again
RTELEM_TYPE_TEXTPARAGRAPH (4) - You have seen the result already
RTELEM_TYPE_TEXTRUN (3) - same as paragraph
RTELEM_TYPE_TABLECELL (7) - overwrites on the mail icon of the original mail
RTELEM_TYPE_DOCLINK (5) - VB error while executing
RTELEM_TYPE_FILEATTACHMENT
RTELEM_TYPE_OLE (9) - VB error while executing
RTELEM_TYPE_SECTION (6) - VB error while executing
I hope to show you tomorrow how NotesPeek might help you how to find the right position to insert your text.
Any progress?
ASKER
Got held up in other projects, Sorry. I am now free and will be able to look into this issue now.
ASKER
using notespeek didnt help solve the problem!! But my sincere thanks to Sjef Bosman for taking me this far! Much appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But still this is open ended!! But I would definitely give the points to Sjef Bosman for helping me till here!! Thanks for everything
Maildb.GetAllUnreadDocumen
instead of
Maildb.db.GetAllUnreadDocu
I hope this helps !