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!
Solved! Go to Solution.
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}
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}
Ah thank you so much!! I updated that to reference the loop variable, not the entire list, and it worked!