Script is getting date/time in ISO format like thi...
# suitescript
k
Script is getting date/time in ISO format like this
var apiDate = "2021-04-21T14:00:00.000+00:00"
, I am then using moment.js and N/Format to format the apiDate to date/time object in NetSuite, like below. however, when trying to set tbpDate into a custom Date/Time field, I am getting
You have entered an Invalid Field Value [object Object]
error. can someone help?
Copy code
var rawDate = moment(apiDate);
var tbpDate = format.format({
  type: format.Type.DATETIME,
  value: rawDate
})
s
you are giving format.format a moment object, which I would not expect to work
Have you tried just using the ISO format and setText to set your field value?
k
setText didn't throw any error, but it also didnt set any value/text to the date/time custom field, when passing the ISO string directly
b
suitescript works with Date objects, not moment objects
get the Date from the moment before using with suitescript
alternatively format it to match your user's date time settings and then use it with Record.setText
k
I updated the code to this:
Copy code
var apiDate = "2021-04-21T14:00:00.000+00:00";
var rawDate = moment(apiDate).toDate();
var tbpDate = format.format({
  type: format.Type.DATETIME,
  value: rawDate
})

new_tracking_rec.setValue({
    fieldId: 'custrecord_tracking_date',
    value: tbpDate
});
and still getting same error
b
use setValue with a Date, use setText with a string
k
when I switched to setText like below, I dont get an error but nothing is set
Copy code
new_tracking_rec.setText({
    fieldId: 'custrecord_tracking_date',
    value: tbpDate
});
b
thats not setText
k
sorry, I updated it just now
after using Format in the above code, the date I am getting is of type string and setText is not assigning anything
b
pay closer attention to setText Parameters
k
shoot, need to use text instead of value, thank you!