SOLVED

Velocity script based on stage value in opportunity

Go to solution
aayushror
Level 2

Velocity script based on stage value in opportunity

Hi There, 

I am trying to write a velocity script to pull data from opportunity list items, but I'm running into an issue when a record has more than one opportunity - the script isn't differentiating between opportunities even though I'm adding the opportunity stage as unique identifying criteria.

#if( $display.alt($OpportunityList.Stage.equals("Documents Collection")) )
#foreach( $oppty in $OpportunityList.Stage.equals("Documents Collection") )
#if ( $display.alt($oppty.Primary_Program__c.contains("Video Game Design and Animation")))

#if( !$display.alt($oppty.Government_Photo_ID_Received__c,"").isEmpty() )
Thank you for providing a valid Government Photo ID
#end
#if( !$display.alt($oppty.Status_In_Canada_Doc_Received__c,"").isEmpty() )
Thank you for providing valid proof of your status in Canada
#end
#if( !$display.alt($oppty.Letter_of_Intent_Received__c,"").isEmpty() )
Thank you for sending your Letter of Intent
#end
#if ( !$display.alt($oppty.All_Transcripts_Received__c ,"").isEmpty())
Thank you for providing Transcript
#end
#end
#end
#end

This is what I have. 

Can someone please tell me what I am missing?

 

Thanks in advance 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script based on stage value in opportunity

This code can’t be doing what you intend.

 

You can’t loop over the Stage field of the OpportunityList. The OpportunityList is literally a list (ArrayList), it doesn’t have its own fields. You loop over the OpportunityList and which gives you a loop variable to work with.

 

The pattern is:

#foreach( $item in $someList )
## work with $item
#end

 

View solution in original post

8 REPLIES 8
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script based on stage value in opportunity

This code can’t be doing what you intend.

 

You can’t loop over the Stage field of the OpportunityList. The OpportunityList is literally a list (ArrayList), it doesn’t have its own fields. You loop over the OpportunityList and which gives you a loop variable to work with.

 

The pattern is:

#foreach( $item in $someList )
## work with $item
#end

 

aayushror
Level 2

Re: Velocity script based on stage value in opportunity

is there a way I can loop it only for items inside the opportunity list which has the stage value set to "Documents Collection" because we have different opportunity lists inside the same lead and the only thing which differs is "stage"

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script based on stage value in opportunity


is there a way I can loop it only for items inside the opportunity list which has the stage value set to "Documents Collection" because we have different opportunity lists inside the same lead and the only thing which differs is "stage"

You always loop over all the items: there’s no prefiltering on #foreach.

 

You wouldn’t have “different opportunity lists inside the same lead”. You have one OpportunityList per lead.

 

Inside the loop, you can check anything you want.

#foreach( $item in $someList )
#if( $item.someProperty.equals("some value") )
## do something
#else
## do something else
#end
#end

 

aayushror
Level 2

Re: Velocity script based on stage value in opportunity

Hi Sanford, 

I changed my code to what you suggested however it still doesn't solve the problem of differentiating the different opportunity lists 

#if( !$OpportunityList.isEmpty())
#foreach( $oppty in $OpportunityList )
#if ( $display.alt($oppty.Primary_Program__c.contains("Video Game Design and Animation")))

#if( $display.alt($oppty.Government_Photo_ID_Received__c,"").isEmpty() )
<li>Please submit a valid Government Photo ID</li>
#end
#if( $display.alt($oppty.Status_In_Canada_Doc_Received__c,"").isEmpty() )
<li>Please submit a valid proof of your status in Canada</li>
#end
#if( $display.alt($oppty.Letter_of_Intent_Received__c,"").isEmpty() )
<li>Please send your Letter of Intent</li>
#end
#if ( $display.alt($oppty.All_Transcripts_Received__c,"").isEmpty())
<li>Please provide your Transcript</li>
#end

#end
#end
#end

 

aayushror
Level 2

Re: Velocity script based on stage value in opportunity

I don't know why it doesn't show the image in my last reply, but this is what I have opportunity_image.PNG

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script based on stage value in opportunity

You’ve been saying “different opportunity lists” but there is one opportunity list, OpportunityListOn a business level you may conceive of the list as containing sub-lists based on properties of each oppty, but this isn’t materialized in any technical way. Just one big list.

 

Without seeing a dump of your list with all of its fields, it’s impossible to say if your logic will work on your data (because you haven‘t shown the entire list with actual Velocity names + values). But it’s the correct approach. Make sure the list has has items; loop over the list; work with each item in the list.

 

 

aayushror
Level 2

Re: Velocity script based on stage value in opportunity

ok then is there a way to differentiate between these 2 opportunities when they are using the same fields? 

no..PNG

doc-2.PNGdoc-1.PNG

currently, that script is returning value for empty as well as not empty, because the custom fields inside these opportunities use the same field. 

What I want to do is if the stage for opportunity is "Document Collection" only then use the custom fields inside that opportunity and ignore if the stage is "Cancel".

I don't even know if it's possible or not. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script based on stage value in opportunity

As noted above

#if( $oppty.stage.equals("Document Collection") )
## do something
#elseif( $oppty.stage.equals("Cancel") )
## do something else
#elseif( $oppty.stage.equals("Yet another stage value") )
## do yet another thing
#end