Solved

Stripping Data from a Lotus Note

Posted on 2009-07-13
4
201 Views
Last Modified: 2013-12-18
I will be receiving a Lotus Note and need to build an agent to strip the fields and assign the data to variables.  The body of each note will be something like this:

Contact:  John Doe
Phone:  555-1234
Location:  San Antonio, TX
Problem:  Client is trying to start windows and is receiving an application error.
Severity:  High

I need to get the values for each field from the body of the note.  The problem is, I'm not sure how long each field will be.  Surely I'm not the only person that has tried this.  Does anyone have some sample code that I can review?  Thanks.
0
Comment
Question by:UPRRDevelopers
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 24839500
Here's some LotusScript code that will do the trick.

There are 3 pieces of code below:

 - An agent that works on the current, open memo.
 - GetMemoText function needed by the agent.
 - ParseData function needed by the agent.

Sub Initialize

	

	Dim ws As New NotesUIWorkspace

	Dim memo As NotesDocument

	Dim body As String

	Dim contact As String, phone As String, location As String, problem As String, severity As String

	Set memo = ws.CurrentDocument.Document

	body = GetMemoText(memo)

	

	contact = ParseData(body, "Contact:", Chr(10))

	phone = ParseData(body, "Phone:", Chr(10))

	location = ParseData(body, "Location:", Chr(10))

	problem = ParseData(body, "Problem:", Chr(10))

	severity = ParseData(body, "Severity:", Chr(10))	

	

	Msgbox "Contact: " & contact & Chr(10) & _

	"Phone: " &  phone & Chr(10) & _

	"Location: " &  location & Chr(10) & _

	"Problem: " &  problem & Chr(10) & _

	"Severity: " &  severity

	

End Sub
 
 

Function GetMemoText(memo As NotesDocument)

	

	Dim sess As New NotesSession

	sess.ConvertMime = True

	GetMemoText = memo.GetItemValue("Body")(0)

	

End Function
 
 

Function ParseData(Byval body As String, Byval tagStart As String, Byval tagEnd As String) As String

	

	Dim parts As Variant

	If (Instr(1, body, tagStart, 5) = 0) Then Exit Function

	parts = Split(body, tagStart)

	If (Instr(1, parts(1), tagEnd, 5) = 0) Then ParseData = Trim(parts(1)) Else ParseData = Trim(Strleft(parts(1), tagEnd))

	

End Function

Open in new window

0
 

Author Comment

by:UPRRDevelopers
ID: 24839787
Outstanding!  It works perfectly.  I changed the agent to fire when an email is delivered to the mailbox, but it's not doing anything.  Is there a trick to make this run automatically when an email is delivered to the mailbox?
0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 500 total points
ID: 24840048
Yes.

You won't be able to use the agent above with an agent set to  "before new mail arrives" or "after new mail has arrived" because those trigger types do not have access to any front-end classes.  The example above gets a handle to the selected document using NotesUIWorkspace, which is a front-end class.  Also, the msgbox function only writes to the log file when used in a back-end agent.

Also, you should be aware that the two "mail-in" trigger types are quite different in how they are used.

Before new mail arrives
  • you can only have one agent in a database that is set to this type.
  • if you have a spam filter installed, you may already have a spam agent in your mail file that is using this type.
  • only one document is processed at a time, so it is much slower than the "after" trigger.
  • mail delivery is delayed slightly while the agent runs.
  • get a handle to the document using the NotesSession.DocumentContext property
After new mail has arrived
  • you can have an unlimited number of agents of this type.
  • you can process documents in batches.
  • mail delivery is not delayed.
  • get a handle to all unprocessed documents using the NotesDatabase.UnprocessedDocuments property.
Here's a simple example of an agent that works on "after new mail has arrived".  I don't know what you want to do with the data, so this agent just retrieves it, but does nothing with it.

Sub Initialize

	

	Dim sess As New NotesSession

	Dim db As NotesDatabase

	Dim dc As NotesDocumentCollection

	Dim doc As NotesDocument

	Dim body As String

	Dim contact As String, phone As String, location As String, problem As String, severity As String

	

	Set db = sess.CurrentDatabase

	Set dc = db.UnprocessedDocuments

	

	Set doc = dc.GetFirstDocument

	Do While (Not doc Is Nothing)

		

		body = GetMemoText(doc)

		

		contact = ParseData(body, "Contact:", Chr(10))

		phone = ParseData(body, "Phone:", Chr(10))

		location = ParseData(body, "Location:", Chr(10))

		problem = ParseData(body, "Problem:", Chr(10))

		severity = ParseData(body, "Severity:", Chr(10))

		

		' do something with the data here.

		

		Set doc = dc.GetNextDocument(doc)

		

	Loop

	

End Sub

Open in new window

0
 

Author Closing Comment

by:UPRRDevelopers
ID: 31602803
That's exactly what I needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lotus Notes 8.0 Forward emails for 30 days. 8 93
Adjusting times for a meeting room 3 139
Event in Notes Form after open and visible 10 217
External emails not coming through 3 100
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now