Please forgive my lack of knowledge as I have just started coding the script.
I'm trying to create the script token which retrieves the date "Field93__c" in $OpportunityList and show the date which is 6 month after the date of "Field93__c".
But the below script can work for the lead which has the only one opportunity. And it does not work correctly for the lead which has several opportunities.
How should I correct?
#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"))
#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
お問い合わせにてご回答可能
#end
And it does not work correctly for the lead which has several opportunities.
What do you mean by working correctly here? FYR, by default, the sorter.sort function sorts data in Ascending order, if you want it to sort in descending order instead, you should add ":desc" suffix:
#set( $sortedUpdated = $sorter.sort($OpportunityList,"Field93__c:desc"))
What I mean by "working correctly" is as follows:
Precondition
User A : 1 Opportunity(X) in the OpportunityList , which has Field93__c (May 1st, 2023).
User B : 2 Opportunity (Y, Z) in the OpportunityList, Opportunity Z has Field93__c (May 1st, 2023).
Expected behavior
User A : 2023年11月1日 should be outputted.
User B: 2023年11月1日 should be outputted.
Actual behavior
User A : 2023年11月1日 is outputted.
User B : Contact Customer support is outputted.
How should I correct my script to output for User A and B like an expected behavior?
Just to confirm, are your dates stored in the format you've shared in the above comment (i.e., "May 1st, 2023") or in the ISO8601DateOnly format (i.e., yyyy-MM-dd) per the parameter in convert.toCalendar() in your script? The alphabetical date-like strings in the ISO format can be sorted using the sort function w/o converting them to Date objects since they're designed to alphabetize properly. However, for the dates stored in the long-date format ("May 1st, 2023") or non-ISO date-like formats, you'd have to first convert them to Date type first by looping over the $OpportunityList once and adding a new Date property to each object record. You'd be able to sort them then.