Skip to main content
Level 2
December 30, 2021
Solved

Velocity script within opportunity custom field

I've been trying to populate field within my opportunity custom field and keep defaulting my token. Not really sure why it's not pulling the contract_start_date but it may have to do with the Day_until_contract_start_date field since it's a calculated sfdc field. Does anyone have experience with using velocity to pull any opportunity custom field?

 

#foreach ( $Opportunity in $OpportunityList ) #set ($OpportunityList = $OpportunityList + 1) #if (${OpportunityList.Days_Until_Contract_Start_Date__c} == "42") #set ($CSDdate = "${Opportunitylist.Contract_Start_Date__c}") #else #set ($CSDdate = "Unavailable") #end #end $CSDdate
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
December 30, 2021

There are a number of fundamental code errors here.  (And the calculated field part isn‘t relevant.)

 

Let me review.

 

#set ($OpportunityList = $OpportunityList + 1)

Here you’re attempting to add an Integer (mathematically) to a List instance. This doesn’t do anything (it silently fails) not sure what you’re actually intending.

 

#if (${OpportunityList.Days_Until_Contract_Start_Date__c} == "42")

Multiple problems here.

 

First, don’t use formal reference (curly brace) syntax inside directives. They’re only necessary for output or, in some cases, inside strings.

 

Second, don’t use the double-equals sign as it has unexpected behavior. Always use the  .equals() method.

 

So at the very least, syntax-wise, you should start with this:

#if( $OpportunityList.Days_Until_Contract_Start_Date__c.equals("42") )

 

However, this still doesn’t make logical sense. You’re checking the property Days_Until_Contract_Start_Date__c of the entire List object. Not of items in the list, but of the whole list. That’s just a null result. You mean to check the property of individual items in the list.

 

If you’re trying to scan all the items in a list for the (first) item with a certain property value, with a fallback if not found, do it like so:

#set( $CSDdate = "Unavailable" ) #foreach( $Opportunity in $OpportunityList ) #if( $Opportunity.Days_Until_Contract_Start_Date__c.equals("42") ) #set( $CSDdate = $Opportunity.Contract_Start_Date__c ) #break #end #end ${CSDdate}

5 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
December 30, 2021

There are a number of fundamental code errors here.  (And the calculated field part isn‘t relevant.)

 

Let me review.

 

#set ($OpportunityList = $OpportunityList + 1)

Here you’re attempting to add an Integer (mathematically) to a List instance. This doesn’t do anything (it silently fails) not sure what you’re actually intending.

 

#if (${OpportunityList.Days_Until_Contract_Start_Date__c} == "42")

Multiple problems here.

 

First, don’t use formal reference (curly brace) syntax inside directives. They’re only necessary for output or, in some cases, inside strings.

 

Second, don’t use the double-equals sign as it has unexpected behavior. Always use the  .equals() method.

 

So at the very least, syntax-wise, you should start with this:

#if( $OpportunityList.Days_Until_Contract_Start_Date__c.equals("42") )

 

However, this still doesn’t make logical sense. You’re checking the property Days_Until_Contract_Start_Date__c of the entire List object. Not of items in the list, but of the whole list. That’s just a null result. You mean to check the property of individual items in the list.

 

If you’re trying to scan all the items in a list for the (first) item with a certain property value, with a fallback if not found, do it like so:

#set( $CSDdate = "Unavailable" ) #foreach( $Opportunity in $OpportunityList ) #if( $Opportunity.Days_Until_Contract_Start_Date__c.equals("42") ) #set( $CSDdate = $Opportunity.Contract_Start_Date__c ) #break #end #end ${CSDdate}
Translate
Jo_Pitts1
Community Advisor
Community Advisor
December 30, 2021

Drat.. now I'll discard my draft LOL!

Translate
SanfordWhiteman
Level 10
December 30, 2021
Next time do a Quick Reply and say I've got this. 🙂
Translate