Link to home
Start Free TrialLog in
Avatar of UPRRDevelopers
UPRRDevelopers

asked on

Stripping Data from a Lotus Note

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.
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

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

Avatar of UPRRDevelopers
UPRRDevelopers

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's exactly what I needed.