I have a function that counts the number of attendees in a schedule class data and assign the next seat number according to what the count is. It works in Infopath but does not work on an Infopath Web form. In the Infopath Web form, it always returns one. I have searched and searched for an another but to no avail. Her is the code. I was wondering if anyone would know how to do this using rules. I tried figuring out how to use rules but could not.
Public Function setSeatNum() As Integer
Dim xPath As XPathNavigator = DataSources("SharePoint Training").CreateNavigator()
Dim ns As XmlNamespaceManager = Me.NamespaceManager
Dim SeatIter As XPathNodeIterator = xPath.Select("/dfs:myFields/dfs:dataFields/dfs:SharePoint_Training/@Seat__", ns)
Dim classDate As XPathNodeIterator = xPath.Select("/dfs:myFields/dfs:dataFields/dfs:SharePoint_Training/@Class_Date", ns)
Dim xForm As XPathNavigator = Me.CreateNavigator()
Dim formClassDate As Date = xForm.SelectSingleNode("/my:SharePointTraining/my:dClassDate", ns).Value
Dim seatNum As XPathNavigator = xForm.SelectSingleNode("/my:SharePointTraining/my:seat", ns)
Dim availSeats As XPathNavigator = xForm.SelectSingleNode("/my:SharePointTraining/my:AvailSeats", ns)
Dim cnt As Integer
Dim dClassDate As Date
While (SeatIter.MoveNext())
classDate.MoveNext()
dClassDate = classDate.Current.Value
If formClassDate = dClassDate Then
cnt = cnt + 1
End If
If formClassDate > dClassDate Then
Exit While
End If
End While
If cnt > 1 Then
seatNum.SetValue(cnt)
availSeats.SetValue(CStr((10 - cnt)))
ElseIf cnt = 0 Then
seatNum.SetValue(cnt + 1)
availSeats.SetValue(CStr(10))
Else
seatNum.SetValue(cnt + 1)
availSeats.SetValue(CStr(10) - cnt)
End If
'clean up
xPath = Nothing
ns = Nothing
SeatIter = Nothing
classDate = Nothing
xForm = Nothing
formClassDate = Nothing
seatNum = Nothing
availSeats = Nothing
End Function
Thanks, in advance
Mike