SOLVED

Re: Velocity script within opportunity custom field

Go to solution
Dan-Pacifico
Level 2

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 
2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script within opportunity custom field

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}

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script within opportunity custom field

You have an extra set of parentheses there, so it definitely doesn’t work in the way you’re expecting!

 

Anyway, to check if a string is empty, don’t use the ! operator. Use explicit isEmpty().

#if( $Opportunity.Contract_Start_Date__c.isEmpty() )

 

For not-empty, you can use the !in conjunction with isEmpty():

#if( !$Opportunity.Contract_Start_Date__c.isEmpty() )

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script within opportunity custom field

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}
Jo_Pitts1
Level 10 - Community Advisor

Re: Velocity script within opportunity custom field

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script within opportunity custom field

Next time do a Quick Reply and say I've got this. 🙂
Dan-Pacifico
Level 2

Re: Velocity script within opportunity custom field

Thanks for looking at this @SanfordWhiteman  If i'm understanding what you're saying if i want to scan if the Contract_Start_Date is "not empty" set the $CSDdate with the Contract_Start_Date token I should be able to use this snippet:

 

#if( !$Opportunity.Contract_Start_Date__c() )
  #set( $CSDdate = $Opportunity.Contract_Start_Date__c )

 

 

Also, this works! want to make sure i'm not running a shaky wild card using the '!$'  for is not empty. I appreciate all the help with this.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script within opportunity custom field

You have an extra set of parentheses there, so it definitely doesn’t work in the way you’re expecting!

 

Anyway, to check if a string is empty, don’t use the ! operator. Use explicit isEmpty().

#if( $Opportunity.Contract_Start_Date__c.isEmpty() )

 

For not-empty, you can use the !in conjunction with isEmpty():

#if( !$Opportunity.Contract_Start_Date__c.isEmpty() )