This message was deleted.
# suitescript
s
This message was deleted.
e
You'll want to turn your strings into
Date
instances, then you can use the
N/format
module to put them in the correct date format
d
Do you know how specifically I can implement that? This is currently causing the same error message. var dateFields = ['prevdate']; // extend as needed for (var bodyFieldId in bodyFieldMap) { if (readOnlyFields.indexOf(bodyFieldId) !== -1) { continue; // Skip system-generated fields } var value = bodyFieldMap[bodyFieldId]; // Convert ISO strings to Date objects for valid date fields if (dateFields.indexOf(bodyFieldId) !== -1 && typeof value === "string") { try { log.debug('Date Field', bodyFieldId + ': ' + value); value = format.parse({ value: value, type: format.Type.DATE }); } catch (e) { log.error('Date Field Error', 'Failed to convert ' + bodyFieldId + ': ' + value); } } try { ia.setValue({ fieldId: bodyFieldId, value: value }); } catch (e) { log.error('Body Field Error', 'Failed to set ' + bodyFieldId + ': ' + e.message); } }
a
it looks like you're just parsing the incoming string into a date object, you need to then format.format that date object into the appropriate format. also I wouldn't just reuse the value variable like that, it should be fine but you're not really saving much so just use a different var with a different name
d
I tried it, but it is still giving me an error. My code: if (dateFields.indexOf(bodyFieldId) !== -1 && typeof value === "string") { try { log.debug('Date Field', bodyFieldId + ': ' + value); var parsedDate = new Date(value); // Convert ISO string → Date object log.debug('Converted Date', bodyFieldId + ': ' + parsedDate); value = format.parse({ value: value, type: format.Type.DATE }); log.debug('Parsed Date', bodyFieldId + ': ' + value); } catch (e) { log.error('Date Field Error', 'Failed to convert ' + bodyFieldId + ': ' + value); } }
Do you know what might be the issue?
a
you're using
format.parse
, you need to use
format.format
... I'm not sure how i can simplify the advice more
1
d
thanks