I am trying to develop a token (in this case a piece of code that runs inside a bigger VBScript) that returns information from an XML that is supplied by the 3rd-party software to a word plugin using bookmarks to provide parameters to the tokens.
So here is what is going on,
XmlDoc.SetProperty "SelectionLanguage", "XPath"
ReturnData = vbNullString
Public Function GetParameterXml()
GetParameterXml = _
"<Parameters>" & _
"<Parameter Value='Last_Hearing' Code='L' Description='Last_Hearing' Type='Combo'>" & _
"<Options>" & _
"<Option Code='' Description='True' Value='True' />" & _
"<Option Code='' Description='False' Value='False' />" & _
"</Options>" & _
"</Parameter>" & _
"</Parameters>"
End Function
Dim oNode : Set oNode = XmlDoc.SelectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Setting/CourtroomMinutes/Comment")
Dim lastHearing : Set lastHearing = Parameters.Item( BookMark, "Last_Hearing" )
If IsNull(lastHearing) Then
lastHearing = False
End If
stop
If lastHearing.Value = "True" Then
Dim dateNodes : Set dateNodes = XmlDoc.SelectNodes("/Record/CelloXml/Integration/Case/Hearing/Setting/HearingDate")
Dim mostRecentHearingDate
Dim dateNode
Dim todaysDate
todaysDate = Date
Dim dateList : Set dateList = CreateObject("System.Collections.ArrayList")
For Each dateNode In dateNodes
dateList.Add CDate(dateNode.Text)
Next
dateList.Sort()
Dim tempDate
For Each tempDate In dateList
If tempDate < todaysDate Then
mostRecentHearingDate = tempDate
End If
Next
mostRecentHearingDate = CStr(mostRecentHearingDate)
Set oNode = XmlDoc.selectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Setting[HearingDate/text()='" & mostRecentHearingDate & "']/CourtroomMinutes/Comment")
End If
If Not oNode Is Nothing Then
ReturnData = oNode.text
Else
ReturnData = vbNullString
End If
Everything works the way that I want it to up until
Set oNode = XmlDoc.selectSingleNode("/Record/CelloXml/Integration/Case/Hearing/Setting[HearingDate/text()='" & mostRecentHearingDate & "']/CourtroomMinutes/Comment")
I needed dateList
to hold dates(or date literals) because I assumed that I would get a bad sort if I tried to sort the dates as a string rather than an actual date, so I converted the text from the node to a date(or date literal) and added it to dateList
When I was done with all the calculations then I needed a string to run in my XPath, if I hard code the date(as a string{08/05/2014}) into the XPath query it works, but when I turn mostRecentHearingDate
into a string using CStr
then oNode
is Set to Nothing
The Node exists and holds data
So,
If you do
dim mostRecentHearingDate
mostRecentHearingDate = CDate("08/05/2014")
mostRecentHearingDate = CStr(mostRecentHearingDate)
mostRecentHearingDate = "8/5/2014" not "08/05/2014" it drops the leading "0"
try
mostRecentHearingDate = Right("0"&DatePart("m",mostRecentHearingDate),2) & "/" & Right("0"&DatePart("d",mostRecentHearingDate),2) & "/" & DatePart("YYYY",mostRecentHearingDate)
That yields
08/05/2014