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!
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!
Share Improve this question edited Sep 11, 2020 at 22:29 quarks 35.4k82 gold badges308 silver badges546 bronze badges asked Mar 1, 2019 at 10:45 Filip WichaFilip Wicha 131 silver badge4 bronze badges2 Answers
Reset to default 4Invalid date value (must be D/M/YYYY)
This means ffDate
is not a date object.
A few things to note first
- record.setValue requires value to be dateTime object.
- If you pass invalid dateTime value to format.format, it returns
option.value
which is not a dateTime object. - If you have a date object, you don't need to format it before using
record.setValue
. setText
requires string to be properly formatted in user format, so its better to usesetValue
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
.
Simple answer:
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);
invoiceRecord.setValue({
fieldId: "trandate",
value: dateObj,
ignoreFieldChange: true
});
Explanation : setValue for a Date field accept a javascript DateObj so no need to format.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745132138a4613022.html
评论列表(0条)