Function Overview
- Input: A transaction date in string format.
- Processing: Converts the string into a valid date object.
- Output: The full year extracted from the date object.
- Error Handling: Logs error and returns
null in case of exceptions.
/**
* Retrieves the last two digits of the fiscal year from a given transaction date.
*
* @param {string} tranDate - The transaction date in string format.
* @returns {string|null} - The last two digits of the fiscal year, or null if an error occurs.
*/
define(['N/format', 'N/log'], function(format, log) {
function getFiscalYearNew(tranDate) {
try {
let dateOBJ = format.parse({
value: tranDate,
type: format.Type.DATE
});
let year = dateOBJ.getFullYear();
return String(year).slice(-2);
} catch (e) {
log.error({ title: 'Error @ getFiscalYearNew', details: e });
return null;
}
}
return { getFiscalYearNew };
});