Hello everyone, does anyone face this error ```{...
# suitescript
m
Hello everyone, does anyone face this error
Copy code
{"type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"Invalid date value (must be M/D/YYYY)","stack":
here is my code
Copy code
fmt.parse({ type: fmt.Type.DATE, value: adoption[column.label] })
b
not enough code shared
the thing to know about date fields is that you use setValue with a Date
you use setText with a string
if you dont know the difference between a string and a Date, you will suffer greatly here until you do
with the code you shared, my guess is that you are trying to use format.parse, in which case you need to know how formatting failures are handled
format.parse will return the input value if it fails to parse it, it will not throw an error
m
Copy code
const colValue = adoption[column.label] && column.col_type == 'date'
                                ? fmt.parse({ type: fmt.Type.DATE, value: adoption[column.label] })
                                : adoption[column.label];

                            fieldata[column.label] = colValue;
                                                        
                            if (adoption[column.label])
                            {
                                newRecord.setValue({
                                    fieldId: column.fieldId,
                                    value: colValue
                                });
                                fieldata[column.fieldId] = value;
                            }
consider
adoption[column.label] })
is equal to
"7/15/2023"
b
still havent shared enough code
m
What do you want to know
b
again, if i cant toss your code in the debugger and have it produce output, its not enough
you get the generic advice that setValue only works with a Date
the error you are seeing is what happens when you try to set it with a string
m
Request
full code
b
ReferenceError, tableInfo is not defined
when debugging, you can start from the beginng and work forwards
or start at the end and work backwards
m
OK
b
starting at the beginning means starting from the first line and checking that each line does what you expect
starting at the end means starting at the last before the error and checking that each line does what you expect
its extremely favorable in both cases to reduce the number of lines you are testing to the absolute minimum
you dont really want to go through 140 lines of code
you want to go throguh the 10 or so that are causing the problem
for example
Copy code
const colValue =
  adoption[column.label] && column.col_type == "date"
    ? fmt.parse({ type: fmt.Type.DATE, value: adoption[column.label] })
    : adoption[column.label];

fieldata[column.label] = colValue;

if (adoption[column.label]) {
  newRecord.setValue({
    fieldId: column.fieldId,
    value: colValue,
  });
  fieldata[column.fieldId] = value;
}
is a reasonable amount of code to work with
and to work with that, you need to hardcode
adoption
,
column
and i guess newRecord and fielddata to the values you expect them to be
and then run the code and make sure you get the error and then you can check that each line does what you want it to do
m
can you debug this var format = require('N/format'); var parsedDate = format.parse({ value: '7/5/2023', type: format.Type.DATE });
this is working fine
b
that is code that is not portable between different accounts
it will run in all accounts without error
but
parsedDate
will be the string '7/5/2023' in accounts where the date format is not MM/DD/YYYY
or worse, it will be the wrong Date in accounts where the date format is DD/MM/YYYY
the important thing for you is that parsedDate is a Date and not a string, and that it is the Date you are expecting it to be