Velocity script email token issue | Community
Skip to main content
Level 3
March 16, 2017
Question

Velocity script email token issue

  • March 16, 2017
  • 1 reply
  • 2456 views

I'm working with a script that pulls checkbox responses from a form field to a response email through an email script token. Script is as follows:

#set( $singleInterests = $lead.documentsDigital.split(";") )

#if( $singleInterests.size() )

#foreach( $singleInterest in $singleInterests ) 

## ${singleInterest}

<a href="info.gepower.com/rs/232-DKG-508/images/${singleInterest}">${singleInterest}</a><br>

#end

#end

I have 4 other fields and created another script for each in the same token that is structured just like the one above, but with the field name changed. I'm getting some weird behavior...when I test, the response email contains links to documents that I did not check. I tried putting all 5 fields into one script, but I don't think I have the syntax right.

Here's what I tried:

#set( $singleInterests = $lead.documentsDigital.split + $lead.documentsServiceAgreements.split + $lead.documentsUpgrades.split +  $lead.documentsServiceCenter.split  + $lead.documentsGenerator.split (";"))

Any suggestions would be greatly appreciated!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
Level 10
March 16, 2017

I tried putting all 5 fields into one script, but I don't think I have the syntax right.

Mmm no, you don't.

#set( $singleInterests = $lead.documentsDigital.split + $lead.documentsServiceAgreements.split + $lead.documentsUpgrades.split + $lead.documentsServiceCenter.split + $lead.documentsGenerator.split (";"))

This is adding functions together.  Without getting too far into it, let's say that's definitely not what you want.

If you have multiple multiple-interest fields:

#set( $lead.allMultipleInterestFields = [

  $lead.documentsDigital,

  $lead.documentsServiceAgreements,

  $lead.documentsUpgrades

] )

#set( $singleInterests = $display.list($lead.allMultipleInterestFields,";").split(";") )

#if( $singleInterests.size() )

You have the following interests:

#foreach( $singleInterest in $singleInterests )

${singleInterest}

#end

#end

N_A_CAuthor
Level 3
March 16, 2017

OK, that's very helpful, thank you. I tried putting that in my token and made sure all of the fields are checked on the right, saved. But when I tried to approve my response email, I got this error:

Validation Error approving WC-2017-03-PS-WTUI-Conference.Email-V2 —

An error occurred when procesing the email Body!

Encountered "]" near

  $lead.documentsServiceCenter,

  $lead.documentsGenerator,

] ) 

#set( $singleInterests = $display.list($lead.allMultipleInterestFields,";").split(";") ) 

#if( $singleInterests.size() ) 

Do you know why it's not liking the bracket?

SanfordWhiteman
Level 10
March 16, 2017

Can you post your token here (not just the error)? And please try to use the syntax formatting/highlighting feature. It's really hard to to read code that isn't in a monospace font and set off from text.