If the date field data is null, show the different message | Community
Skip to main content
New Participant
June 11, 2023
Solved

If the date field data is null, show the different message

  • June 11, 2023
  • 1 reply
  • 1745 views

I want to do the following 

If the lead has the date data of"Field93__c" in $OpportunityList, I would like to show 2 month after date of it.

If they do not have, I would like to show the text "Contact Customer Support".

I created the following script token 

#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( $sortedList = $sorter.sort($OpportunityList,"Field93__c"))
#set( $dateObj = $convert.toCalendar(
$convert.parseDate(
$sortedList.get(0).Field93__c,
$ISO8601DateOnly,
$defaultLocale,
$defaultTimeZone
)
) )
#if($dateObj)
$dateObj.add($calConst.MONTH, 2)
${date.format($JapanDate, $dateObj, $defaultLocale, $defaultTimeZone
)}
#else
Contact Customer Support

But it does not work. How should i correct ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

The flaw in this code is that you can’t sort a null value.

 

If there’s > 1 Opportunity and the value of

Field93__c

 is null for any item in

$OpportunityList

the sort errors out and $sortedUpdated is never set (it is also null).

1 reply

Darshil_Shah1
Community Manager
June 11, 2023

Could you try the below 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" ) #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,2) ${date.format( $JapanDate, $inputDate, $defaultLocale, $defaultTimeZone )} #else Contact Customer Support #end
SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
June 12, 2023

The flaw in this code is that you can’t sort a null value.

 

If there’s > 1 Opportunity and the value of

Field93__c

 is null for any item in

$OpportunityList

the sort errors out and $sortedUpdated is never set (it is also null).

Darshil_Shah1
Community Manager
June 12, 2023

Gotcha! That's a very valid point- for most of my use cases, I usually have to sort on the standard updatedAt field so I don't run into that error. I do recollect that we can't mix types with a generic SortTool.sort, and comparing a null with a Date value, a Boolean with a String, or a Number with a Boolean, are all mixed types, and hence would run into errors. For handling this, would you recommend iterating over the list and filling in any null with an empty-like value of the same type (in this particular case the date type) first?