Restlet script - getting error: Cannot find functi...
# suitescript
g
Restlet script - getting error: Cannot find function format in object Sat Mar 11 2023 000000 GMT-0800 (PST). array is: "tranDate":"03/11/2023", script:
Copy code
recItemFulfillment.setValue({
              fieldId: 'trandate',
              value: new Date(stTranDate).format('MM/DD/YYYY')
also tried keeping it simple however doesn't work:
Copy code
recItemFulfillment.setValue({
              fieldId: 'trandate',
              value: new Date(stTranDate)
w
Read up on how to use new Date(). Doesn't look like you can use strings formatted in illogical date formats like "MM/DD/YYYY"
🇪🇺 1
😂 1
a
1. where are you getting stTranDate from? 2. do you log stTranDate anywhere? 3. what do you think the format method is on a JS date object... because there isn't one? 4. if you're trying to use the NS format module you'd have to do format.parse or format.format and then pass the date in as option param
I'm not sure what array you're talking about since there isnt an array in your code, and what you listed after "array" looks like an object not an array?
the error is exactly what I would expect when trying to call a format method (which doesn't exist) on a date object. you said the second version also "doesn't work" but you didn't say how it fails so its difficult to troubleshoot
g
@Anthony OConnor thanks for the response..
logging var stTranDate = objSalesOrder.tranDate;
this is what the request looks like:
'[
{
"salesOrderExternalId":"ABC",
"tranDate":"03/11/2023",
"status":"C",
"salesOrderId":"123",
"salesOrderLocation":"3",
"linesToFulfill": [
{
"line":1,
"quantity":1
},
{
"line":2,
"quantity":1
}
]
}
]'
originally was this: there's no error message, it's just not recognising it and setting today's date..
if (stTranDate) {
recItemFulfillment.setValue({
fieldId: 'trandate',
value: new Date(stTranDate)
});
a
is your
recItemFulfillment
created in dyanmic mode?
if it is then the order you set field values matters, if you set the date before you set subsidiary, customer, sales order too maybe? not 100% sure with fulfillments... anyway that can reset any values you've previously tried to set so make sure you're doing the trandate set value AFTER other header valus you're setting. this only applies to dynamic mode tho, if you're in static mode none of that matters and this code looks fine
Copy code
if (stTranDate) {
    recItemFulfillment.setValue({
        fieldId: 'trandate',
        value: new Date(stTranDate)
     });
    ...
}
j
what value is in stTranDate and what type of variable? What is the result if you do this
log.debug({title: 'stTranDate', details: 'value is ' + stTranDate + ' and typeof is ' + typeof stTranDate});
💯 1
setValue expects a date object
so if
stTranDate
is not a date object, you can turn it into one using
format.parse()
** fixed thanks Watz
oops yes
format.parse()
sorry I always get those backwards
b
I recommend the opposite, only use format.parse on strings you get from netsuite, it uses the current user's date and time format, which can change
stick to using the Date constructor if you can guarantee the format you input are one of the ones it supports
g
thanks all.. Anthony has helped, moving the trandate as the last body field update resolved it...