SOMETIMES getting NULL values while using IIF condition and javaCast( "null", "" ) in ColdFusion

Viewed 50

In XXX.cfc file.,

var SCOPE = structNew();
var result = structNew();
result['completeDate'] = iif( LEN(SCOPE.inductionKeyInfo.inductionCompleteDate) GT 0, "SCOPE.inductionKeyInfo.inductionCompleteDate", javaCast( "null", "" ) );

Sometimes, result['completeDate'] returns null though LEN(SCOPE.inductionKeyInfo.inductionCompleteDate) GT 0 is true.

I found another way of doing it,

result['completeDate'] = LEN(SCOPE.inductionKeyInfo.inductionCompleteDate) ? SCOPE.inductionKeyInfo.inductionCompetentDate : javaCast( "null", "" );

But wondering which one is the best way of doing it?

Could anyone please help me if you find any issues here?

Thank you in advance!!

0 Answers
Related