I have a workflow action script with the code show...
# suitescript
m
I have a workflow action script with the code shown below. Basically it’s running after submit and comparing
oldRecord
and
newRecord
to look for differences. 
context.oldRecord
is being passed to
getRecordData()
function but for some reason its value is
null
so I’m getting “TypeError: Cannot read property ‘getValue’ of null”.  This workflow is not set to run on “Create”, only “View and Update”, so
oldRecord
should always exist. Any idea why this would happen? This script works as expected in our sandbox but it has not worked in production.
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType WorkflowActionScript
 * @NModuleScope Public
 */
define(['N/log', './lodash'], function (log, _) {
    function onAction(context) {
        const oldRecord = getRecordData(context.oldRecord);
        const newRecord = getRecordData(context.newRecord);

        return _.isEqual(oldRecord, newRecord) ? 'F' : 'T';
    }

    function getRecordData(record) {
        const recordData = {
            lines: []
        };

        // 'record' is null here
        recordData.entity = record.getValue({ fieldId: 'entity' });
        recordData.usertotal = record.getValue({ fieldId: 'usertotal' });

        // Do some more stuff here

        return recordData;
    }

    return {
        onAction
    };
});
s
I would not expect oldRecord to exist in View mode, and I would not expect there to be an afterSubmit context in VIEW mode either. Not sure if that is the problem, though
m
Thanks! I agree, VIEW mode doesn’t trigger an afterSubmit event, so this action wouldn’t be called. I can see that it’s happening only when a bill is edited. I’ve opened a support case because the same script works in one of our sandboxes.
s
Am i crazy or shouldnt the return function be
onAction: onAction
b
In ES6, you can just use the key as shorthand if the key and value is exactly the same name.