SOLVED

Re: Email Script token using in Email From field?

Go to solution
Kacper_Gawlik1
Level 2

Email Script token using in Email From field?

Hi All,

Can you confirm if we can use Email Script token in Email's From field? We have a case, where such token is used in email body, and it works fine however, we are unable to send test email, using other person field to populate data from this token when it is also used in From field.
pastedImage_0.png
Weird thing is that it works perefectly in Preview email option.

Can you please advise?

Thanks,

Kacper

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script token using in Email From field?

Use a collection-centric approach here:

#set( $peopleBySession = {

"Sydney May 05|Sydney October 19" : "Person 1",

"Sydney June 06|Sydney July 17|Sydney August 19" : "Person 2",

".*Sydney.*" : "Person 3",

".*Munich.*" : "Person 4",

".*Warsaw.*" : "Person 5",

".*Madrid.*" : "Person 6",

".*" : "Some other persion"

} )

#foreach( $rule in $peopleBySession.entrySet() )

#if( $lead.session.matches($rule.getKey()) )

$rule.getValue()

#break

#end

#end

Also, remember (I seem to say this on every Velocity thread) you should not be using formal notation, let alone quoted formal notation, in simple #set statements.

This:

#set( $mainsession = "${lead.session}" )

should be this:

#set( $mainsession = $lead.session )

(Although you don't necessarily need an intermediate variable at all if you reduce repetition.)

View solution in original post

8 REPLIES 8
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script token using in Email From field?

It works fine.

You shouldn't be using Send Sample to test Velocity tokens. Use real emails only (this is noted all over past Nation posts).

Kacper_Gawlik1
Level 2

Re: Email Script token using in Email From field?

Hi Sanford,

What do you mean by real email?

I tried sending that via Smart Campaign, still able to receive only those that do not have token in From field.

Any thoughts? Script may have some flaws?

Thanks,

Kacper

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script token using in Email From field?

Script may have some flaws?

Certainly. The feature is supported so the error has to be elsewhere.

Kacper_Gawlik1
Level 2

Re: Email Script token using in Email From field?

So we are trying to receive something as per below:
pastedImage_5.png

With above set up population in From field does not work.

It seems to be working with simplified logic:

pastedImage_6.png

Can you please validate what we are doing wrong? Any chance that we can achieve something closer to what you can see on the first screen?

We are assuming that we may have field mainsession with value Sydney only, so we need default logic for this part a well.

Thanks,

Kacper

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script token using in Email From field?

Please don't post screenshots.

When posting code, highlight it using the Advanced Editor's syntax highlighter so it's readable and copyable.

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script token using in Email From field?

Use a collection-centric approach here:

#set( $peopleBySession = {

"Sydney May 05|Sydney October 19" : "Person 1",

"Sydney June 06|Sydney July 17|Sydney August 19" : "Person 2",

".*Sydney.*" : "Person 3",

".*Munich.*" : "Person 4",

".*Warsaw.*" : "Person 5",

".*Madrid.*" : "Person 6",

".*" : "Some other persion"

} )

#foreach( $rule in $peopleBySession.entrySet() )

#if( $lead.session.matches($rule.getKey()) )

$rule.getValue()

#break

#end

#end

Also, remember (I seem to say this on every Velocity thread) you should not be using formal notation, let alone quoted formal notation, in simple #set statements.

This:

#set( $mainsession = "${lead.session}" )

should be this:

#set( $mainsession = $lead.session )

(Although you don't necessarily need an intermediate variable at all if you reduce repetition.)

Kacper_Gawlik1
Level 2

Re: Email Script token using in Email From field?

Appreciate your help and sorry for print screens.
This works as expected!!

Can you clarify what these parts of function do?
Especially .entrySet, rule.getKey, rule.getValue?

#foreach( $rule in $peopleBySession.entrySet() )

#if( $lead.session.matches($rule.getKey()) )

$rule.getValue()

#break

#end

#end

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script token using in Email From field?

Can you clarify what these parts of function do?
Especially .entrySet, rule.getKey, rule.getValue?

Sure.

$peopleBySession (declared with the {}) is a built-in Java object, an ordered map (LinkedHashMap) with key-value pairs. The keys and values, in this case, are both Strings, though the keys (left-hand-side) are used as regexp patterns (strings with specific meaning).

#foreach iterates over the map's .entrySet(), entry-by-entry (entry = a key-value pair).

.getKey() gets the current entry's String key (left-hand-side), .getValue() gets its String value (right-hand-side).