Send Notes mail from an XML call
The next function to look into is “getParams”. This function begins the process of extracting our message parameters from the XML.
Function getParams(s As NotesSession, strInput As String) As Boolean
' function to parse the XML stream posted to this agent, and grab the parameters
getParams = False
On Error Goto errorCatch
Dim domParser As NotesDOMParser
Dim nodeDoc As NotesDOMDocumentNode
Dim nodeList As NotesDOMNodeList
Dim nodeNode As NotesDOMElementNode, nodeNode2 As NotesDOMElementNode
Dim x As Integer, y As Integer
Set domParser = s.CreateDOMParser
' set the input to the xml text stream
Call domParser.parse(strInput)
Set nodeDoc = domParser.Document
For x = 0 To Ubound(arrParams) ' loop through our array of parameters
' get list of nodes for arrParams(x), first check looks to see if the node exists
Set nodeList = nodeDoc.GetElementsByTagName(arrParams(x))
If nodeList.NumberOfEntries < 1 Then
If getRequiredStatus(x) Then
' node is missing and it is required
getParams=False
Exit Function
Else
Goto endFor
End If
Else
' we have the node, let's grab the value node
Set nodeNode = nodeList.getItem(1)
End If
' so we have a parameter node, do we have a value node?
Set nodeList = nodeNode.GetElementsByTagName("value")
If nodeList.NumberOfEntries < 1 Then
If getRequiredStatus(x) Then
getParams = False
Exit Function
Else
Goto endFor
End If
Else
For y = 1 To nodeList.NumberOfEntries ' for nodes with multiple "value" nodes
Set nodeNode2 = nodeList.GetItem(y)
' let's check to see if the node exists but is empty
If nodeNode2.HasChildNodes Then
If Not setArrays(x,y,nodeNode2) Then
getParams = False
Exit Function
End If
Else
' if empty, check to see if required
If getRequiredStatus(x) Then
getParams = False
Exit Function
End If
End If
Next
End If
EndFor:
Next
getParams = True
Exit Function
errorCatch:
strOut = "Error in doSendMessage:getParams in line: " & Erl() & " error$: " & Error$
bSuccess = False
Exit Function
End Function
So here we loop through our arrParams array and extract the nodes from the XML. There are two other functions that are called from this function; “getRequiredStatus” which is where we can find out if the parameter is required, and “setArrays” which will determine which global variable to set based upon which parameter we are extracting. First we’ll look at the “getRequiredStatus” function.
Function getRequiredStatus(x As Integer) As Boolean
' determine if a parameter is required based upon index value of x
' required fields are 0->SendTo, 3 -> Subject, 4 -> body text, 5 -> From
On Error Goto errorCatch
getRequiredStatus = False
If x = 0 Then
strOut = "sendto is a required parameter"
getRequiredStatus=True
Elseif x=3 Then
strOut = "subject line is a required parameter"
getRequiredStatus=True
Elseif x=4 Then
strOut = "body text is a required parameter"
getRequiredStatus=True
Elseif x=5 Then
strOut = "from is a required parameter"
getRequiredStatus=True
End If
Exit Function
errorCatch:
strOut = "Error in doSendMessage:getRequiredStatus in line: " & Erl() & " error$: " & Error$
getRequiredStatus = False
Exit Function
End Function
I mentioned near the beginning that the strOut variable was a container for any error messages sent back to the user. So if we are missing a required parameter we will set the strOut variable to our error message, return false to the calling function, which will error out the entire process, thus returning the error to the client.
March 30th, 2006 at 3:30 am
Hi there. Came across this article via codestore http://www.codestore.info/store.nsf/unid/BLOG-20060329, via Johan Känngård http://johankanngard.net/2005/12/13/sending-html-mails-via-lotusscript/ then you!
We have a PC on our network, that is used to run an Excel program, the Excel file is then emailed to various users (they should really stick it in a central repository etc…). The sending user could log into their Web Access mail file, but as an interesting exercise, I would like to give this a go. I keep getting a 404 error when trying to download your sample database.
Great site, interesting articles.
Nick