I am trying to get the old Value on a record. My code snippet is as follows :
const beforeSubmit = (scriptContext) => {
var param_Old_Item = runtime.getCurrentScript().getParameter({name:'custscript_old_item'});
var param_New_Item = runtime.getCurrentScript().getParameter({name:'custscript_new_item'});
var type = scriptContext.type;
var allowedTypes = [
scriptContext.UserEventType.CREATE,
scriptContext.UserEventType.EDIT
];
if (allowedTypes.indexOf(type) == -1) {
return;
}
var sub_item_new = scriptContext.newRecord.getValue({
fieldId: 'custrecord_item123'
});
/* var ChargeRec = scriptContext.oldRecord;
var sub_item_old = ChargeRec.getValue({
fieldId: 'custrecord_item123'
}); */
var sub_item_old = scriptContext.oldRecord.getValue({
fieldId: 'custrecord_item123' });
log.debug({
title: 'sub_item_old',
details: sub_item_old
});
The oldRecord value is throwing an error - TypeError: Cannot read property 'getValue' of null [at Object.beforeSubmit
Please help.
Expecting to get the oldRecord Value in beforesubmit
oldRecordwill always benullduring aCREATEevent. The record is being created, so there is nothing in the database yet to retrieve or compare to.