SOLVED

Re: Velocity Opportunity Sort Token

Go to solution
Barry_Moffat2
Level 2

Velocity Opportunity Sort Token

We have some emails where we use script tokens to sort the opportunities on a person's record by a datetime field and output a data value from the opportunity with the newest datetime in that specific field. However, we're finding that the tokens periodically fail, resulting in the email soft bouncing (the sender name and email address are two of the fields output by these tokens). 

However, when I look at the records on which they fail, the required sort fields are all present on the opportunity at the point that the email sends, so I'm at a loss as to why they fail. 

 

Has anyone encountered this? Attached example of the token script: 

 

#if( !$OpportunityList.isEmpty() )



#set( $OpportunityListRecentFirst = $sorter.sort($OpportunityList,["vu_vurpurpose:desc","vu_vurattached:desc"]) )
${OpportunityListRecentFirst[0].rss_hbcemail}
#end

 

 

All fields are checked on the token sidebar. The first datapoint is a string with only two possible values, and the second is the datetime field used to sort by most recent value. 

 

We use a Microsoft Dynamics CRM in case that's pertinent, with the dynamics stakeholder grid deployed so that multiple people can be associated with an individual opportunity

 

Any insights or suggestions would be much appreciated.   

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Opportunity Sort Token

Barry and I deciphered this offline, it was actually a question of unexpected null values (which had been thought impossible due to CRM-side rules when creating Opportunities).

View solution in original post

15 REPLIES 15
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Opportunity Sort Token

Please highlight the code using the syntax highlighter so it's readable. Then we'll continue.

syntax_vtl.png

Barry_Moffat2
Level 2

Re: Velocity Opportunity Sort Token

#if( !$OpportunityList.isEmpty() )



#set( $OpportunityListRecentFirst = $sorter.sort($OpportunityList,["vu_vurpurpose:desc","vu_vurattached:desc"]) )
${OpportunityListRecentFirst[0].rss_hbcemail}
#end

Sorry, my bad. Thanks for taking a look, Sanford.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Opportunity Sort Token

Could you edit your initial post instead? B/c otherwise this keeps happening when people look at old posts.

Barry_Moffat2
Level 2

Re: Velocity Opportunity Sort Token

Yes, done.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Opportunity Sort Token


However, we're finding that the tokens periodically fail, resulting in the email soft bouncing (the sender name and email address are two of the fields output by these tokens). 

Are you sure none of the fields (neither the fields you're sorting on, nor the field used for output) are null-able?

 

How are you verifying that "required sort fields are all present on the opportunity at the point that the email sends"? You'd have to send a real email (not sample) with the full $OpportunityList in the body (of course hard-coding the From:/Reply-To: info in this case to avoid the failure). What's the output then?

Barry_Moffat2
Level 2

Re: Velocity Opportunity Sort Token

They are null-able. I was verifying before by looking at the individual's activity log and reviewing the Update Opportunity activity that triggered the campaign (which has a log of all fields as they were at that moment I believe). 

 

I did what you suggested and dropped the full Opportunity List into an email (nice trick by the way) and all the opportunities in the list have values in those fields. It also outputted some other fields that we use in the email using similar script tokens (presumably because they were still in the text version?) 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Opportunity Sort Token


I did what you suggested and dropped the full Opportunity List into an email (nice trick by the way) and all the opportunities in the list have values in those fields. It also outputted some other fields that we use in the email using similar script tokens (presumably because they were still in the text version?) 


Any fields checked off in the tree will be included when you dump the whole list object.

 

So what output do you get — in the body here, so it doesn't stop the send — when you drop the logic to get the property off the most recent Oppty?

Barry_Moffat2
Level 2

Re: Velocity Opportunity Sort Token

Ah sorry, Sanford, I misunderstood you before and simply made a script token with a single phrase- $OpportunityList, i.e. no logic to sort by most recent. This is what outputted everything I mentioned previously (in ascending order.) 

 

What I think I now understand you actually suggested before was to output the entire sorted opportunity list into the email. Forgive my lack of knowledge, but how do I do that?  I tried this and it output nothing so guess that is wrong.

#if( !$OpportunityList.isEmpty() )



#set( $OpportunityListRecentFirst = $sorter.sort($OpportunityList,["vu_vurpurpose:desc","vu_opportunitycreated","vu_vurattached:desc"]) )
${OpportunityListRecentFirst}
#end

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Opportunity Sort Token

Ah sorry, Sanford, I misunderstood you before and simply made a script token with a single phrase- $OpportunityList, i.e. no logic to sort by most recent. This is what outputted everything I mentioned previously (in ascending order.) 

That was what I meant to start out, so you were following me!

 

Now you have a good comparison: the unsorted list, the sorting does not.  

 

But you reported something strange: if #set-in$OpportunityListRecentFirst fails (which would happen, for a primary example, if any of the values were null) then outputting $OpportunityListRecentFirst should print just the code (the literal String "OpportunityListRecentFirst"), not an empty String.

You're going to need to show me the values of these fields from the $OpportunityList dump, something is off here.