i seriously dont undertsand whats wrong for (var ...
# suitescript
r
i seriously dont undertsand whats wrong for (var fld in objUsageVal) {                 log.debug('objUsageVal[fld]==',objUsageVal[fld]); //objUsageVal[fld]== 07/29/2021           if(objUsageVal[fld])         {           recUsage.setValue({ fieldId: fld, value: objUsageVal[fld]});         } }
Copy code
{
   type: "error.SuiteScriptError",
   name: "INVALID_FLD_VALUE",
   message: "Invalid date value (must be MM/DD/YYYY)",
   stack: [
      "anonymous(N/serverRecordService)",
     
   ],
   cause: {
      type: "internal error",
      code: "INVALID_FLD_VALUE",
      details: "Invalid date value (must be MM/DD/YYYY)",
      userEvent: null,
      stackTrace: [
         "anonymous(N/serverRecordService)",
         
         "anonymous(N/serverRecordService)"
      ],
      notifyOff: false
   },
   id: "",
   notifyOff: false,
   userFacing: false
}
whyyy?????
b
the error message is deceptive
you must use a Date with setValue to set a date field
or you must use a string with setText to set a date field
attempts to set a date field with a string as the value will result in the error you are seeing
r
Copy code
var formattedDateString = format.format({
              value: parsedDateStringAsRawDateObject,
              type: format.Type.DATE
          });
  
  
      //else usageDateFinal = dtUsageDate;
      log.debug("usageDateFinal before set on record", formattedDateString);
  
      objUsageVal["usagedate"] = formattedDateString;
      // Customer, Item and Subscription Plan will be automatically sourced
this is the code just before that
b
is
objUsageVal[fld]
a string or a Date?
r
its a date
b
are you sure
r
should format.format again before setting?
just before setting?
b
the name
formattedDateString
suggests you thought it was a string
r
var parsedDateStringAsRawDateObject = format.parse({               value: usageDateFinal,               type: format.Type.DATE           });
before that
b
format.format documents when it returns a strong and when it returns a Date
r
but still it is getting formatted as suggest
b
a formatted string is still not a Date
a Date is a specific type of Object
r
i dont understand bro
this thing has had me crazy
i even did new date(usageDateFinal)
and tried to format.format that
b
you will need to understand the difference between a string and a Date
r
i guess you are right
b
and need to be able to tell if
objUsageVal[fld]
is a string or Date
j
Why are you even using
format.format
? If you are using setValue, just pass it a date object. No need to format it.