-3

I am trying to find the max of date from json data. But i am getting below error

Message        : "You cannot compare a value of type :Null
Trace:
 at reduce (Unknown)
 at dw::Core::maxBy (line: 5535, column: 3)
 at main (line: 1, column: 248)" evaluating expression: 
 "%dw 2.0 output application/json ---  {  Value2:  (  if (vars.data.Value1 as String != "")   
 (payload maxBy((item) -> item.startDate)).startDate default vars.data.Value1   
 else   ""  ), RCount: sizeOf(payload) }".
Error type      : MULE:EXPRESSION
Element        : executeInterface/processors/8 @ gg:gg.xml:121 (interface)
Element XML      : <set-variable value="#[%dw 2.0 output application/json ---
 {  Value2:  (  if (vars.data.Value1 as String != "")   
 (payload maxBy((item) -> item.startDate)).startDate default vars.data.Value1   
 else   ""  ), RCount: sizeOf(payload) }]" doc:name="interface" doc:id="2c140185-2fc5-4e11-9b78-96fc2ddcfa2f" variableName="interface"></set-variable>
 (set debug level logging or '-Dmule.verbose.exceptions=true' for everything).

The logic written in set variable component is

%dw 2.0
output application/json
---
{
Value2:   
(  if (vars.data.Value1 as String != "")   
(payload maxBy((item) -> item.startDate)).startDate default vars.data.Value1   
 else   ""  
 ),
RCount: sizeOf(payload)
}

while running in the debug mode, found the problem is in maxby statement.

Please suggest.how to fix this issue

aled
  • 21,330
  • 3
  • 27
  • 34
gunjan gupta
  • 51
  • 1
  • 12

1 Answers1

0

The error indicates that something is null when trying to compare. Given that you mentioned the error is at maxBy(), it is probable the the attribute startDate is null or not present in one of the elements. You should show also the values of the transformation so we could confirm it.

UPDATE: I can reproduce the error if the startDate attribute is not present or if it is misspelled. For example if I misspell item.StartDate (wrong uppercase 'S') it produces the error. Make sure the payload and script match exactly.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Thanks for the reply.But there are no nulls in the column.Basically what i am trying to do is finding the max date from the column startdate and storing this date in a variable for further use.Do you have any other way to solve this – gunjan gupta Dec 31 '19 at 04:38
  • You would need share the payload data and structure so we can understand the issue further. Can you reproduce it with a small sample? – aled Dec 31 '19 at 17:42