SOLVED

Email Script Token Goes to Default Value

Go to solution
Itay_Billet4
Level 8

Email Script Token Goes to Default Value

Hi all, we created an email script token that displays the SDR name based on logic on other custom field (POD) and the SFDC type (Lead/Contact)

It seems like it goes to the default condition ("SDR Team Lead"), and the other conditions are not calculated (Even though I checked some examples and it should work). I added below the script:

#if(${lead.SFDC_Type} == "Lead" && ${lead.POD_New__c_lead} == "01. US ENT 1")
#set($sdr_name = "Rep US ENT 1 ")
#elseif(${lead.SFDC_Type} == "Lead" && ${lead.POD_New__c_lead} == "06. US HC 1")
#set($sdr_name = "Rep US HC 1")
#elseif(${lead.SFDC_Type} == "Lead" && ${lead.POD_New__c_lead} == "07. US HC 2")
#set($sdr_name = "Rep US HC 2")
#elseif(${lead.SFDC_Type} == "Lead" && ${lead.POD_New__c_lead} == "02. US ENT 2")
#set($sdr_name = "Rep US ENT 2")

#elseif(${lead.SFDC_Type} == "Contact" && ${lead.POD_New_Contact__c} == "01. US ENT 1")
#set($sdr_name = "Rep US ENT 1")
#elseif(${lead.SFDC_Type} == "Contact" && ${lead.POD_New_Contact__c} == "06. US HC 1")
#set($sdr_name = "Rep US HC 1")
#elseif(${lead.SFDC_Type} == "Contact" && ${lead.POD_New_Contact__c} == "07. US HC 2")
#set($sdr_name = "Rep US HC 2")
#elseif(${lead.SFDC_Type} == "Contact" && ${lead.POD_New_Contact__c} == "02. US ENT 2")
#set($sdr_name = "Rep US ENT 2")
#else
#set($sdr_name = "SDR Team Lead")
#end

##print the SDR name
${sdr_name}

Can you let us know if there's a syntax issue we're missing?

 

Thanks!

 

Itay

 

1 ACCEPTED SOLUTION

Accepted Solutions
Michael_Florin
Level 10

Re: Email Script Token Goes to Default Value

Did you check the respective fields like "SFDC Type" in the right hand side nav of the token?

View solution in original post

4 REPLIES 4
Michael_Florin
Level 10

Re: Email Script Token Goes to Default Value

Did you check the respective fields like "SFDC Type" in the right hand side nav of the token?

SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token Goes to Default Value

We’d need to see the raw values of your relevant fields ($lead.POD_New__c_lead, $lead.POD_New_Contact__c, $lead.SFDC_Type). Otherwise, it’s impossible to know whether the output is expected or not. As Michael mentions, you may not have checked them off in the tree.

 

Regardless, you should be avoiding formal references and the == operator. Both of these can cause hard-to-find bugs. Instead, use simple references and equals().

#if( $lead.SFDC_Type.equals("Lead") && $lead.POD_New__c_lead.equals("01. US ENT 1") )
#set($sdr_name = "Rep US ENT 1 ")
#elseif( $lead.SFDC_Type.equals("Lead") && $lead.POD_New__c_lead.equals("06. US HC 1") )
#set($sdr_name = "Rep US HC 1")
#elseif( $lead.SFDC_Type.equals("Lead") && $lead.POD_New__c_lead.equals("07. US HC 2") )
#set($sdr_name = "Rep US HC 2")
#elseif( $lead.SFDC_Type.equals("Lead") && $lead.POD_New__c_lead.equals("02. US ENT 2") )
#set($sdr_name = "Rep US ENT 2")
#elseif( $lead.SFDC_Type.equals("Contact") && $lead.POD_New_Contact__c.equals("01. US ENT 1") )
#set($sdr_name = "Rep US ENT 1")
#elseif( $lead.SFDC_Type.equals("Contact") && $lead.POD_New_Contact__c.equals("06. US HC 1") )
#set($sdr_name = "Rep US HC 1")
#elseif( $lead.SFDC_Type.equals("Contact") && $lead.POD_New_Contact__c.equals("07. US HC 2") )
#set($sdr_name = "Rep US HC 2")
#elseif( $lead.SFDC_Type.equals("Contact") && $lead.POD_New_Contact__c.equals("02. US ENT 2") )
#set($sdr_name = "Rep US ENT 2")
#else
#set($sdr_name = "SDR Team Lead")
#end

##print the SDR name
${sdr_name}

 

 

Itay_Billet4
Level 8

Re: Email Script Token Goes to Default Value

Hi @SanfordWhiteman, that's correct, I forgot to check the fields that I used on the tree. I did that now and looks like it's working

 

Thanks

 

Itay

Jo_Pitts1
Level 10 - Community Advisor

Re: Email Script Token Goes to Default Value

@Itay_Billet4 ,

I'm thrilled the other guys got you over the line.  I thought I'd comment on the coding itself (in the interest of making your life easier in the future).  

 

This is the approach I'd take:

 

#set( $PODtoSDR = { "01. US ENT 1" : {"SDRName":"Rep US ENT 1"},
                   "06. US HC 1" : {"SDRName":"Rep US ENT 1"},
                   "07. US HC 2" : {"SDRName":"Rep US HC 2"},
                   "02. US ENT 2" : {"SDRName":"Rep US ENT 2"}
                   })

#if( $lead.SFDC_Type.equals("Lead"))
  #set($sdr_name =$PODtoSDR[$lead.POD_New__c_lead].SDRName)
#elseif( $lead.SFDC_Type.equals("Contact") )
  #set($sdr_name =$PODtoSDR[$lead.POD_New_Contact__c].SDRName)
#end

#if (! $sdr_name )
  #set($sdr_name = "SDR Team Lead")
#end

##print the SDR name
${sdr_name}

 

 

So, step wise:

  1. I set up the map between POD and SDR.  
  2. Based on whether the lead is a Lead or Contact I use the appropriate field to get a value for $sdr_name from the map.
  3. if $sdr_name is still empty I give it the default value.
  4. I print the output.

FWIW - I've not had a chance to actually execute my code above, so it's probably got a few errors, but the concept is correct and is super easy to extend (just add more values to the map at the top.. no other code changes required).  If you ended up with different allocation rules for leads vs. contacts, you could create a second value like so

 

#set( $PODtoSDR = { "01. US ENT 1" : {"contactSDRName":"Rep US ENT 1",
                                      "leadSDRName":"Bob"},
                   "06. US HC 1" : {"contactSDRName":"Rep US ENT 1",
                                      "leadSDRName":"Jane"},
                   "07. US HC 2" : {"contactSDRName":"Rep US HC 2",
                                      "leadSDRName":"Mike"},
                   "02. US ENT 2" : {"contactSDRName":"Rep US ENT 2",
                                      "leadSDRName":"Sue"}
                   })

And refer to each of either .contactSDRname or .leadSDRname in the if statement in step 2.

 

Hopefully that is helpful/useful to you (and please take this whole post in that spirit)

 

Cheers

Jo