Velocity Scripting to Display a Contacts Opportunity Owner

Highlighted

Velocity Scripting to Display a Contacts Opportunity Owner

Hi All,

I am trying to create a email velocity script to just show the opportunity owners name in an email as a signature. So basically I am just trying to set the variable to be the actual value on the contacts record. I have tried (see below) but I keep getting an error. Can anyone tell me what I am doing wrong. Thanks.

#set ($opptname = ${OpportunityList.get(0).Oppty_Owner_Email__c})

#if($opptname.equals(""))

Account Rep

#else

$display.(Oppty_Owner_Email__c)

#end

8 REPLIES 8
Highlighted
Level 10 - Community Moderator

Re: Velocity Scripting to Display a Contacts Opportunity Owner

Can you please highlight your code using the Syntax Highlighter?

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

Highlighted
Level 2

Re: Velocity Scripting to Display a Contacts Opportunity Owner

Did you get this sorted Eric Rosenberg‌? I'm curious about it too

Highlighted
Level 10 - Community Moderator

Re: Velocity Scripting to Display a Contacts Opportunity Owner

Eric's code has a clear error, but what are you trying?

Highlighted
Level 2

Re: Velocity Scripting to Display a Contacts Opportunity Owner

I'm trying to create a token for a field called "Onboarding Coordinator", which lives on the Opportunity. I'm trying to put in rules that say if the value is blank, then default to "a team member", (by replicating code that you wrote here actually for first name). I will say that I'm a complete rookie at this and don't understand a lot of the functions yet.

#set( $OnboardingCoordinator = $OpportunityList.get(0).Onboarding_Coordinator_Name__c.trim() ) 
#if(
$OnboardingCoordinator.isEmpty() ||
$OnboardingCoordinator.matches(".*[0-9@._].*") ||
$OnboardingCoordinator.length() < 2 ||
$OnboardingCoordinator.indexOf(" ") == 1
)
a team member##
#else
#set( $OnboardingCoordinator = $OnboardingCoordinator.split(" +")[0] )
$display.capitalize($OnboardingCoordinator.toLowerCase())##
#end
‍‍‍‍‍‍‍‍‍‍‍‍

Here's your original, which works perfectly:

#set( $FirstName = $lead.FirstName.trim() ) 
#if(
$FirstName.isEmpty() ||
$FirstName.matches(".*[0-9@._].*") ||
$FirstName.length() < 2 ||
$FirstName.indexOf(" ") == 1
)
there##
#else
#set( $FirstName = $FirstName.split(" +")[0] )
$display.capitalize($FirstName.toLowerCase())##
#end‍‍‍‍‍‍‍‍‍‍‍‍

Highlighted
Level 10 - Community Moderator

Re: Velocity Scripting to Display a Contacts Opportunity Owner

Looks fine, are you sure the field Onboarding_Coordinator_Name__c is checked off in the tree in Script Editor?

Highlighted
Level 2

Re: Velocity Scripting to Display a Contacts Opportunity Owner

Yes, it's checked off. I should add that when there's a first name in there, the script works. However, when the value is empty it shows as "$display.capitalize($OnboardingCoordinator.toLowerCase())

Screen Shot 2019-08-02 at 9.14.04 AM.png

Highlighted
Level 10 - Community Moderator

Re: Velocity Scripting to Display a Contacts Opportunity Owner

I don't think it's empty, it's null. Which is different. Custom object fields can be true null. Lead fields will be an empty string ("").

Account for this additional condition:

#set( $OnboardingCoordinator = $display.alt($OpportunityList.get(0).Onboarding_Coordinator_Name__c.trim(),"") ) 
Highlighted
Level 2

Re: Velocity Scripting to Display a Contacts Opportunity Owner

Awesome - that worked! Thanks a lot for your help Sanford