Count specific dates in a list don't work - InfoPath Dev
in

InfoPath Dev

Count specific dates in a list don't work

Last post 08-16-2010 06:21 AM by Michael Vasquez. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-05-2010 11:10 AM

    Count specific dates in a list don't work

    I have created a form that schedules the end user to attend a SharePoint Training Class.  The total amount of persons per class is ten.  The class is held every Friday.   What I have done with the InfoPath form is to connect to a data connection on the server and itinerate through all the dates beginning with the next scheduled Friday's class and count how many people are scheduled for that specific date.  Two things will occur.  I will get the next schedule class seat number and also how many seats are available for the class (see code below).   


    Dim xPath As XPathNavigator = DataSources("SharePoint Training").CreateNavigator()    'Where form is submitted
    Dim ns As XmlNamespaceManager = Me.NamespaceManager
    Dim SeatIter As XPathNodeIterator = xPath.Select("/dfs:myFields/dfs:dataFields/dfs:SharePoint_Training/@Seat__", ns)  'Get list of seat numbers
    Dim classDate As XPathNodeIterator = xPath.Select("/dfs:myFields/dfs:dataFields/dfs:SharePoint_Training/@Class_Date", ns) 'Get list of class dates
    Dim xForm As XPathNavigator = Me.CreateNavigator()
    Dim formClassDate As String = CStr(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 String
    Dim sCnt As String

    While (SeatIter.MoveNext())
    classDate.MoveNext()
    dClassDate = Left(classDate.Current.Value, 10)
         

      ‘If the date on the form equals the date from the data connection (SharePoint_Training), count it

         If formClassDate = dClassDate Then
             cnt = cnt + 1
         End If
         
         ‘If the date on the form is greater than the date from the data connection (SharePoint_Training) (old date) then add one to the count, which will be the next
         ‘seat number and then exit the while loop
          
         If formClassDate > dClassDate Then
             cnt = cnt + 1
             Exit While
         End If
    End While

     If cnt > 0 Then
          ‘Set the value of the seat numbeer
          seatNum.SetValue(CStr(cnt))
     End If
    ‘Set the value of the available seats
     sCnt = CStr(11 – cnt)
     availSeats.SetValue(sCnt)

    Why does the above code only works in InfoPath and not on the InfoPath Web form.  If there is one person scheduled for this week’s class the InfoPath will output the next seat number (2) and output the available seats (9).  The InfoPath Web form outputs seat number (1) and outputs the available seats  (10).

     

    Mike V
  • 08-11-2010 12:43 AM In reply to

    Re: Count specific dates in a list don't work

    Hi Mike,

    You don't need code to do this. You can use xpath (InfoPath's macro language) and the eval command. Microsoft's InfoPath blog had an article about 2 years ago on the eval(eval(....)) method. It's pretty cool and we even have it in one of our InfoPath training labs. Send me email if you can't google it.

    Best of luck

    PS> there's also a count function which could be easier. :)

    Patrick Halstead
    Project Manager at Qdabra
  • 08-16-2010 06:21 AM In reply to

    Re: Count specific dates in a list don't work

    I tried the count function and it did not work on a Web based form.  Can't get the eval to work either.  Not sure how to use it.

     

    Mike

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.