Hello, I'm trying to retrieve MAX date value store...
# suitescript
k
Hello, I'm trying to retrieve MAX date value stored in an array. using below code NS throwing error as "_TypeError: Cannot find function max_", need some inputs for (var y = 1; y <= soitems_count; y++) { var soitem_id = soRec.getLineItemValue('item','item', y); nlapiLogExecution('DEBUG', 'Sales Order Item ID', soitem_id); soRec.selectLineItem('item', y); var dates=[]; dates.push(soRec.getCurrentLineItemValue('item', 'custcol_cs_exp_ship_date')); maxdate = dates.max(); nlapiLogExecution('DEBUG', 'Maximum Date', maxdate); soRec.setFieldValue('shipdate',maxdate); }
n
var maxDate=new Date(Math.max.apply(null,dates)); https://stackoverflow.com/questions/7143399/min-max-of-dates-in-an-array
p
You also need to move the max and the setFieldValue out of the line item loop
n
Yeah you're evaluating the array on every iteration.
Only thing I hesitate on with that is, SS1.0 are you getting a date object or string, I suspect the latter 😞