4 Replies Latest reply on Oct 11, 2017 7:57 AM by Sanford Whiteman

    Velocity Script Creating Maps in a Loop

    Nicholas Sewitz

      Hey, I have a velocity script that loops over a custom object, Shows. I want to essentially to create a custom token that if there is only one show in the list does one thing and if there are multiple shows in the list does another thing. I've got that part down, its what happens when there are multiple shows that I am having trouble. The below code will only display one show for $fairMap even though there are 2 in $showList. Ideally if there are multiple shows I want the script to iterate over each show that meets the criterea and output like this (without me having to hardcode obviously [0][1][2][etc]:

       

      I am pleased to share that the online preview of the below fairs:<br><br>

       

      Show Name: $showName[0]<br>

      URL: $showURL[0]<br><br>

      Show Name: $showName[1]<br>

      URL: $showURL[1]<br><br>

      Show Name: $showName[2]<br>

      URL: $showURL[2]<br><br>

       

       

      This is what I have so far. I am trying to store each show name/url in the $fairmap map.

       

      ##Initialize
      
      
      #set ( $showName = false )
      #set ( $x = $date.calendar )
      
      
      
      
      #foreach($show in $Show__cList)
          #set ( $fairPreviewDay = $show.Fair_Autopublish_At__c )
          #set ( $fair_preview_date_object = ${convert.parseDate(${show.Fair_Autopublish_At__c}, 'yyyy-MM-dd')} )
          #set ( $fair_preview_date_days = ${date.whenIs($fair_preview_date_object).days} )
          #set ( $showTriggeredDate = $show.Send_First_Triggered_Email__c )             
          #set ( $showURL = $show.CMS_URL__c )
          #set ( $showListSize = $Show__cList.size() )
          
          
          #if ( $show.Fair_Name__c )
          #set ($showFairName = $show.Fair_Name__c )
          #else
          #set ($showFairName = $show.Name)
          #end 
          
          #if ( $showTriggeredDate && $fair_preview_date_days == 0 )  
            #if ( $showListSize > 1 )
            #set( $FairInfoMap = {  
                "Fair Name: " : $showFairName,
                "URL: " : $showURL } )
            #elseif( $showListSize == 1 )
            I am pleased to share that the official online preview of $showFairName  has launched. Please check out your booth in the CMS: $showURL 
            #end
          #end   
      
      
      #end
      
      
      #if ( $showListSize > 1 )
      I am pleased to share that the online preview of the below fairs have launched:<br><br>
          $FairInfoMap
      #end