Jira Code: HTL-7
Setting values to the Date-Time field. Using the Format Module. We can use the Format Module to format the Date-Time field, Date field. The date that has to be formatted should be in the string format.
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/file', 'N/url', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/ui/serverWidget', 'N/format'],
function (file, url, search, runtime, record, https, serverWidget, format) {
var main = {
beforeSubmit: function (scriptContext) {
var records = scriptContext.newRecord;
log.debug("records", records)
var date = new Date();
var month = date.getMonth() + 1;
date = month + "/" + date.getDate() + "/" + date.getFullYear();
log.debug("date", date)
var initialFormattedDateString = date;
var parsedDateStringAsRawDateObject = format.parse({
value: initialFormattedDateString,
type: format.Type.DATE
});
log.debug("parsedDateStringAsRawDateObject", parsedDateStringAsRawDateObject)
var formattedDateString = format.format({
value: parsedDateStringAsRawDateObject,
type: format.Type.DATETIME
});
log.debug("formattedDateString", formattedDateString)
records.setText({
fieldId: 'custentity60',
text: formattedDateString,
ignoreFieldChange: true
})
return true;
}
};
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function () {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
}
}
};
return main;
});