SOLVED

Re: Velocity Script - display message if no results match

Go to solution
Anonymous
Not applicable

Velocity Script - display message if no results match

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

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script - display message if no results match

Please use syntax highlighting when posting code (there's no VTL highlighter but use Java):

pastedImage_3.png

It sounds like you're talking about filtering the output and then outputting a message if all output was filtered.

Because of Velocity's limited loop syntax, you'll need to do this with a separate "sentinel" variable.

#set( $nothingFound = true )

#foreach( $thing in $things )

#if( <you found something you're looking for> )

#set( $nothingFound = false )

## <and do other stuff>

#end

#end

#if( $nothingFound == true )

## <tell user nothing was found, since $nothingFound is still true>

#end

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Script - display message if no results match

Please use syntax highlighting when posting code (there's no VTL highlighter but use Java):

pastedImage_3.png

It sounds like you're talking about filtering the output and then outputting a message if all output was filtered.

Because of Velocity's limited loop syntax, you'll need to do this with a separate "sentinel" variable.

#set( $nothingFound = true )

#foreach( $thing in $things )

#if( <you found something you're looking for> )

#set( $nothingFound = false )

## <and do other stuff>

#end

#end

#if( $nothingFound == true )

## <tell user nothing was found, since $nothingFound is still true>

#end

Anonymous
Not applicable

Re: Velocity Script - display message if no results match

Ahh makes sense - Thank you! Still new to velocity scripting