Select specific opportunity (by type) and extract relative values | Community
Skip to main content
New Participant
March 10, 2023
Solved

Select specific opportunity (by type) and extract relative values

  • March 10, 2023
  • 1 reply
  • 1330 views

I've spent the afternoon pouring through some discussion posts here trying to solve this myself, but I think I'm hitting the point where I'll benefit from just asking.

 

I'm trying to use dynamically insert data (the Service Start Date) from the Opportunity Object into the body of an email, however multiple Opps exist on these records so I'm trying to isolate a specific one -- by either the Opp Type (preferred) or Stage (backup if Type won't work). From what I've read, I believe I need to us a foreach to sort through the Opportunities, but my filter must be incorrect because it's disregarding the stage/type and still selecting the most recent Opp. 

 

Here's what I have: 

 

#set( $SSDate = "Unavailable" ) #foreach( $Opportunity in $OpportunityList ) #if( $Opportunity.Stage.equals("Closed Won") ) #set( $SSDate = $OpportunityList.Service_Start_Date__c ) #break #end #end ${SSDate}

 

I'm a little new to VTL so I hope I've interpreted other posts correctly. Appreciate any direction! 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

In line #4, why are you using $OpportunityList.Service_Start_Date__c? Shouldn't you be referencing the loop variable, i.e., $Opportunity for the value assignment instead of referencing the entire list object using $OpportunityList?

 

#set( $SSDate = "Unavailable" ) #foreach( $Opportunity in $OpportunityList ) #if( $Opportunity.Stage.equals("Closed Won") ) #set( $SSDate = $Opportunity.Service_Start_Date__c ) #break #end #end ${SSDate}

 

 

1 reply

Darshil_Shah1
Darshil_Shah1Accepted solution
Community Manager
March 11, 2023

In line #4, why are you using $OpportunityList.Service_Start_Date__c? Shouldn't you be referencing the loop variable, i.e., $Opportunity for the value assignment instead of referencing the entire list object using $OpportunityList?

 

#set( $SSDate = "Unavailable" ) #foreach( $Opportunity in $OpportunityList ) #if( $Opportunity.Stage.equals("Closed Won") ) #set( $SSDate = $Opportunity.Service_Start_Date__c ) #break #end #end ${SSDate}

 

 

New Participant
March 13, 2023

Ah thank you so much!! I updated that to reference the loop variable, not the entire list, and it worked!