Hello everyone, Getting this error when I am sett...
# suitescript
u
Hello everyone, Getting this error when I am setting value in date field Invalid date value (must be MM/DD/YYYY)
{"expectedReceiptDate":"11/17/2021","shipDate":"11/01/2021"}
Code :
Copy code
var formatedShipDate = new Date(data.shipDate);
var formatedExpectedReceiptDate = new Date(data.expectedReceiptDate);

formatedShipDate = format.format({
    value: formatedShipDate,
    type: format.Type.DATE
})

formatedExpectedReceiptDate = format.format({
    value: formatedExpectedReceiptDate,
    type: format.Type.DATE
})

rec.setValue({
    fieldId: 'custrecord_bk_mcb_por_ship_date',
    value: formatedShipDate
});

rec.setValue({
    fieldId: 'custrecord_bk_mcb_por_expec_receipt_date',
    value: formatedExpectedReceiptDate
});
b
use setValue with a Date, use setText with a string
u
Tried it. But it didnt work it just left the fields empty without any error.
b
what did your attempt look like
u
poRequest.setText({                 fieldId: 'custrecord_bk_mcb_por_ship_date',                 value: formatedShipDate             });             poRequest.setText({                 fieldId: 'custrecord_bk_mcb_por_expec_receipt_date',                 value: formatedExpectedReceiptDate             });
Used setText just like you said
b
Use it correctly: Record.setText
u
Thats what I did
b
read the doc
u
poRequest.setText() poRequest is the Record
b
what are the 3 parameters to setText?
u
Oh
thanks
This might just be it
s
if you were using typescript you probably would have avoiding this entire conversation
because it would give you a clear error message before you even finished the
.setText
line in your editor 🙂
and it would have saved battk's time too. win win!
a
@stalbert I've actually been curious about this for some time, can you expound a bit on the benefits of TS vs JS (and downsides)?
s
I've expounded ad nauseum on this topic 🙂 Anyway, one of the biggest benefits especially relevant to us SuiteScripters is related to time waste. To run a script we have to take time to upload a script then time for some manual steps to actually execute the code. TypeScript can catch many errors before you even upload the code. That time savings alone is significant and accumulates.
a
🙂 Thanks, got it. And downsides?
How steep is the learning curve?
s
Downside is you have a small bit of setup to do in most IDEs to tell it to automatically compile your TS files to JS behind the scenes.
a
Got it, thank you!
s
Also, once you start to enjoy typing there is a risk of wanting to type ALL THE THINGS! Typescript is forgiving and you don't have to have types for everything.
337 Views