3 Replies Latest reply on Jul 10, 2018 10:39 AM by Sanford Whiteman

    Custom Token - Display Name of Day

    James Randolph

      Hello,

       

      I'd like to make a script that finds the current day, then adds two business days to that day, and displays the appropriate name of the day.

       

      For example:

      I'd like to arrange a call for today or {{my.TwoDaysAhead}}.

      I'd like to arrange a call for today or Wednesday.

       

      All I have is getting the current date

      #set ($today = $date.getDate())

       

      Any help is appreciated.

       

      Thanks,

       

      James    

        • Re: Custom Token - Display Name of Day
          Sanford Whiteman

          You need to read (and digest) the seminal post on date math in Velocity: https://blog.teknkl.com/velocity-days-and-weeks/

           

          The date format for the long day-of-week is "EEEE":

           

          $date.format("EEEE", $yourDateObj)
          
            • Re: Custom Token - Display Name of Day
              James Randolph

              Thank you for your help, I'm getting closer but still no luck. This is what I have:

               

              #set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )

              #set( $defaultLocale = $date.getLocale() )

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

              #set( $ret = $calNow.setTimeZone($defaultTimeZone) )

              #set( $calConst = $field.in($calNow) )

              #set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )

              #set( $ISO8601DateOnly = "yyyy-MM-dd" )

               

               

              #set( $twoBizDays = $calNow.add($calConst.DAY_OF_WEEK,2)

               

               

              #set( $businessDays = [

                $calConst.MONDAY,

                $calConst.TUESDAY,

                $calConst.WEDNESDAY,

                $calConst.THURSDAY,

                $calConst.FRIDAY

              ] )

              #if( $businessDays.contains($calNow.get($calConst.DAY_OF_WEEK)) )

              today or ${twoBizDays}

              #end

               

              I also noticed the Link to "FlowBoost", would that give me the ability to use JavaScript in tokens instead of Java's Velocity?

               

              Thanks again

                • Re: Custom Token - Display Name of Day
                  Sanford Whiteman

                  There's a syntax error in there, but more important [a] you want to add DATE for days, not DAY_OF_WEEK, and also [b] .add() mutates the original Date, it doesn't create new one ($ret just means a void return, I should've used $void maybe to make that more clear).

                   

                  So you want to create a new Date (starting it as today) and mutate that one to be 2 days from now.

                  #set( $twoBizDays = $date.getCalendar() )
                  #set( $ret = $twoBizDays.add($calConst.DATE,2) )
                  

                   

                  "FlowBoost", would that give me the ability to use JavaScript in tokens instead of Java's Velocity?

                  No, FlowBoost is scripting for flows so it can't change email content like Velocity.

                   

                  You can actually use JS inside Velocity, although it's probably not worth it unless you're an ECMAScript 3-vintage expert and don't mind missing ES5+ stuff: Use JavaScript within Velocity (if you must)

                  1 of 1 people found this helpful