email script - if field(s) contains a & b, write x | Community
Skip to main content
Charles_Sander1
Level 4
March 19, 2019
Solved

email script - if field(s) contains a & b, write x

  • March 19, 2019
  • 1 reply
  • 3455 views

I was hoping to solve this problem with segmentation... but realized that I can't, if the user makes multiple choices. But I'm not finding Velocity syntax for what seems like it should be a simple thing:

If person's field contains "a" do "x" ... and a multiple, if contains "a" and "b" . I

This is based off a form with multiple choice checkboxes. That populates a string field with something like "000012; 000015" - if they've checked those two options.

I know ==, I've found ".contains" but I can't seem to figure out "!does NOT contain"

EDIT: I tried this - which didn't work at all, but probably gives a clear picture of what I'm trying to do:

#if ( index($lead.resourceChoice1, '0001' ) == 1) && ( index($lead.resourceChoice1, '0002' ) == -1)

#set($assettype = "Chose 1, but not 2 - content")

#elseif ( index($lead.resourceChoice1, '0001' ) == -1) && ( index($lead.resourceChoice1, '0002' ) == 1)

#set($assettype = "Chose 2, but not 1 - content")

#elseif ( index($lead.resourceChoice1, '0001' ) == 1) && ( index($lead.resourceChoice1, '0002' ) == 1)

#set($assettype = "Chose 1 & 2 - content")

#elseif ( index($lead.resourceChoice1, '0001' ) == -1) && ( index($lead.resourceChoice1, '0002' ) == -1)

#set($assettype = "Chose None - content")

#else

#set($assettype = "default content")

#end

##print it out

${assettype}

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

Can't just scan the whole string like that, you need to split it on the delimiter.

#set( $resourceChoices = $lead.resourceChoice1.split("; ") )

#if( $resourceChoices.contains("0001") & !$resourceChoices.contains("0002") )

does contain 0001, but not 0002

#end

etc.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
March 19, 2019

Can't just scan the whole string like that, you need to split it on the delimiter.

#set( $resourceChoices = $lead.resourceChoice1.split("; ") )

#if( $resourceChoices.contains("0001") & !$resourceChoices.contains("0002") )

does contain 0001, but not 0002

#end

etc.

Charles_Sander1
Level 4
March 19, 2019

Awesome! That did the trick! I came across something like that, but it seemed like it was for creating an array - and I didn't think what I was doing above was an array.

Is that what I missed? ".contains" is for arrays? or maybe I'm just overthinkin' it?

SanfordWhiteman
Level 10
March 19, 2019

I came across something like that, but it seemed like it was for creating an array

Yes, splitting a String into an ArrayList -- which is indeed what you want, since you want to treat the String as a collection of values.

".contains" is for arrays? or maybe I'm just overthinkin' it?

String.contains is for Strings, List.contains is for Lists. There's more than one contains method (an infinite number in Java as a whole!).