2 Replies Latest reply on Oct 2, 2017 12:17 PM by Kelly Toomey

    Velocity Script - display message if no results match

    Kelly Toomey

      Hi Everyone!

       

      I have this script created that pulls data from a table if it matches yesterdays date and has a status of active. It is working great but I seem to have hit a road block. What I need to do is have a message display if it runs through the table and nothing matches. When I put in an else if statement - after this statement #if( ($year == $yep) && ($stat == "Active") ) , It displays the message multiple times because it loops through and shows for ever entry that does not match the statement. Any ideas?

       

       

      This is the script that I am using:

      #set( $Calendar = $date.getCalendar() ) 

              #set( $tmp = $Calendar.add($field.in($Calendar).DATE, -1) )

              #set( $yep = $date.format('yyyy-MM-dd',$Calendar) )

              #set( $yep2 = "$yep" )

      ##declare an $countvariable

      #set($count= 0)

      <table border="0">

       

       

      ##begin looping through EventsList

            #foreach($coce_enrollmentid in $coce_enrollmentList)

       

      ##split the date field on '-'

      ##yyyy-MM-dd becomes ['yyyy','MM','dd']

      ##retrieve first array element, the year

      #set ($year = ${coce_enrollmentList.get($count).coce_enrolldate})

              #set ($stat = ${coce_enrollmentList.get($count).statecode})

       

              #set($count = $count + 1)

       

      ##check if $year matches designated year

      #if( ($year == $yep) && ($stat == "Active") )

       

      ##increment $count

      ##create info table row

      <tr>

      ##add Event link

                           #set($entry = $count - 1)

                           #set($enrollnm = ${coce_enrollmentList.get($entry).coce_name} )

       

                           #set($coursenm = ${coce_enrollmentList.get($entry).coce_classtitle} )

                          

                          #set($termguid = ${coce_enrollmentList.get($entry).coce_enrollmentterm} )

                        

      #if ( $termguid == "ca50133d-289b-e411-a488-b4b52f66caec" )

      #set ( $termname = "17TW3" )

      #elseif ( $termguid == "fe3a2e3c-289b-e411-a4f3-b4b52f67c660" )

      #set ( $termname = "17TW4" )

      #elseif ( $termguid == "ff3a2e3c-289b-e411-a4f3-b4b52f67c660" )

      #end

      <td> $enrollnm - $coursenm - Term $termname </td>          

      </tr>

      ##end if statement

      #end

      ##close the loop

      #end

      </table>

      ##print out total events