I created RESTlet which makes it easier to create new Invoice via simple web page with multiple inputs and dropdowns. I'm sending date as D-M-YYYY string using json called invoiceInfo, the date string is a value of trandate.
On the script (Suitescript 2.0) I connect to, I split the trandate, then create a Date object (I use new Number not because of my stupidity, it just works only that way). Then I format the date to Netsuite's desireable format using format.format
. After that I set a value of trandate using formatted date.
var splitedDate = invoiceInfo.trandate.split("-");
var dateObj = new Date(new Number(splitedDate[0]).valueOf(), (new Number(splitedDate[1]).valueOf()) - 1, new Number(splitedDate[2]).valueOf(), 0, 0, 0, 0);
var ffDate = format.format({
value: dateObj,
type: format.Type.DATE
});
invoiceRecord.setValue({
fieldId: "trandate",
value: ffDate,
ignoreFieldChange: true
});
When submitting the Invoice (dynamic mode is set as true) I get an error at line number 83, which is this line
invoiceRecord.setValue({ fieldId: "trandate", value: ffDate, ignoreFieldChange: true });
And got an error like this:
{
"type": "error.SuiteScriptError",
"name": "INVALID_FLD_VALUE",
"message": "Invalid date value (must be D/M/YYYY)",
"stack": ["anonymous(N/serverRecordService)", "<anonymous>(/SuiteScripts/Filip/_wystawianie_faktury_api.js:83)
[...]
When I check it with log.debug I get this:
"invoiceInfo.trandate" is (for example) "2019-03-15"
"dateObj" is "2019-03-15T07:00:00.000Z"
"ffDate" is "15/3/2019"
I have tried many options, for example: -passing hardcoded date string "15/3/2019" I get the same error; -I tried setText instead of setValue and got another error; -I tried changing the date format in @HomeIcon -> Set Preferences and then gave the desired format hardcoded and it still didn't work;
Thanks for help
PS I'm kinda new at writing questions on stack. I tried my best!
Invalid date value (must be D/M/YYYY)
This means ffDate
is not a date object.
A few things to note first
option.value
which is not a dateTime object.record.setValue
.setText
requires string to be properly formatted in user format, so its better to use setValue
instead cause it handles all the conversion etc.So what I suggest is, you pass date in ISO String to the RESTlet, which could easily be converted into date object in NetSuite(using new Date()) and then pass this object directly to record.setValue
.