I am getting a particular error ```{"type":"error....
# suitescript
v
I am getting a particular error
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "INVALID_FLD_VALUE",
  "message": "Invalid date value (must be M/D/YYYY)",
  "stack": [
    "anonymous(N/serverRecordService)",
    "createCashSale(/SuiteScripts/GetItem.js:106)",
    "_get(/SuiteScripts/GetItem.js:24)",
    "anonymous(N/serverRecordService)"
  ],
  "cause": {
    "type": "internal error",
    "code": "INVALID_FLD_VALUE",
    "details": "Invalid date value (must be M/D/YYYY)",
    "userEvent": null,
    "stackTrace": [
      "anonymous(N/serverRecordService)",
      "createCashSale(/SuiteScripts/GetItem.js:106)",
      "_get(/SuiteScripts/GetItem.js:24)",
      "anonymous(N/serverRecordService)"
    ],
    "notifyOff": false
  },
  "id": "",
  "notifyOff": false,
  "userFacing": false
}
I am calling in this way `var subscriptionStartDate = new Date();``
moment(subscriptionStartDate).format("M/D/YYYY")});
b
date fields can be set 2 ways
using setValue with a Date
or using setText with a string formatted via N/format
in general, don't use moment to format strings, it can lead to formatting issues
you should just be able to use subscriptionStartDate by itself to set a date field
v
I am using moment as Format doesn't have 'M/D/YYYY' format
Copy code
salesorder.setValue({fieldId:'subscriptionStartDate',value:moment(subscriptionStartDate).format("M/D/YYYY")});
How to write I am using a custom field
b
you are using setValue
any attempt to set a Date type field using a string will fail with your error message
use a Date if you are trying to use setValue
use a String (created using format.format) if you are trying to use setText
v
Now I am trying
var subscriptionStartDate = moment(new Date()).format("M/D/YYYY");
salesorder.setValue({fieldId:'subscriptionStartDate',value:subscriptionStartDate});
it's still failing
b
you made subscriptionStartDate a string
all attempts at using setValue with a string will fail
either make subscriptionStartDate a Date
or start using setText