If the one opportunity in the opportunityList has the value, how can we detect the opportunity?

nitenichiryu
Level 2

If the one opportunity in the opportunityList has the value, how can we detect the opportunity?

I want to do the following

If the lead has the date data of "Field93__c" in the one of the opportunity in the $OpportunityList, I would like to show 6 month after date of it. And if the lead does not have date data in the any opportunity in the $OpportunityList, I would like to show the text "Contact Customer Support".
(# of the opportunity in the $OpportunityList can be varied based on each lead)

 

I create the following script

 

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("Asia/Tokyo") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $JapanDate = "yyyy年MM月dd日")
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
#foreach( $opportunity in $OpportunityList )
#set( $sortedUpdated = $sorter.sort($opportunity,"Field93__C"))
#if($sortedUpdated[0].Field93__C && !$sortedUpdated[0].Field93__C.isEmpty())
#set( $inputDate = $convert.toCalendar(
$convert.parseDate(
$sortedUpdated[0].Field93__c,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
))
$inputDate.add($calConst.MONTH,6)
${date.format(
$JapanDate,
$inputDate,
$defaultLocale,
$defaultTimeZone
)}
#else
Contact Customer Support
#end
#end

 

 But it does not work. How should i correct ?

Tags (1)
3 REPLIES 3
Phillip_Wild
Level 10

Re: If the one opportunity in the opportunityList has the value, how can we detect the opportunity?

As a starting point, you have "6" in the $inputDate.add command, not 4.

 

Looks like you are also passing the field "F93__c" through to the $inputDate variable rather than "F100__c". If you're trying to add 4 months to the F100 field, you need to reference that in the $inputDate variable, which in turn is passing to your final date formatter.

 

Give it a go!

SanfordWhiteman
Level 10 - Community Moderator

Re: If the one opportunity in the opportunityList has the value, how can we detect the opportunity?

This code doesn’t make sense.

 

You’re iterating (#foreach-ing) over the original Opportunity list.

 

On every iteration, you’re trying to sort the Opportunity Item (not the list!) on a single property. The $opportunity HashMap is not usefully sortable.*

 

You want to sort the $OpportunityList (the list).

 

 

 

 

* Technically it is sortable — its property values will be sorted lexicographically — but that’s not useful/sensible.

nitenichiryu
Level 2

Re: If the one opportunity in the opportunityList has the value, how can we detect the opportunity?

HI 

 I have updated my script as follows. However, it does not work even if the lead has one opportunity..

 

Could you advise?

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("Asia/Tokyo") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $JapanDate = "yyyy年MM月dd日")
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
#set( $sortedUpdated = $sorter.sort($OpportunityList,"Field93__c"))
#foreach ($sortedU in $sortedUpdated)
#if($sortedU[0].Field93__c && !$sortedU[0].Field93__c.isEmpty())
#set( $inputDate = $convert.toCalendar(
$convert.parseDate(
$sortedU[0].Field93__c,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
))
$inputDate.add($calConst.MONTH,6)
${date.format(
$JapanDate,
$inputDate,
$defaultLocale,
$defaultTimeZone
)}
#else
Contact Customer Support
#end
#end

 

$sortedU[0] means 1st opportunity is sortedU array, right?  How should I implement e.g. for 

for (int i = 0; i < 2; i++){
sortedU[i].Field93__c;
}

in Java?