Keir Kettle
11/22/2022, 8:12 AMconst employee = record.load({ type: Types.EMPLOYEE, id: employeeId });
employee.setValue({ fieldId: 'custrecord_our_field_id', value: 21 });
employee.save();
The script throws - “TypeError: Cannot read property \“length\” from null (NLRecordScripting.scriptInit$lib#770)”
Anyone, any ideas?Keir Kettle
11/22/2022, 8:17 AMrustyshackles
11/22/2022, 8:33 AMKeir Kettle
11/22/2022, 8:58 AMCD
11/22/2022, 10:41 AMKeir Kettle
11/22/2022, 11:55 AM/**
* @NApiVersion 2.1
* @NScriptType restlet
*/
define(['N/log', 'N/record'], (log, record) => {
function post(data) {
try {
const { owner } = data;
const employee = updateEmployeeRecord(owner, 1);
return JSON.stringify({ success, error: null, employee });
}
catch (ex) {
log.error('testEmployee - error', ex);
return JSON.stringify({ success: false, error: ex.message });
}
}
function updateEmployeeRecord(owner) {
const employeeRecord = record.load({ type: record.Type.EMPLOYEE, id: owner });
employeeRecord.setValue({ fieldId: 'firstname', value: 'Damien1' });
employeeRecord.save();
return employeeRecord;
}
return {
post
};
});
CD
11/22/2022, 12:02 PMowner
probably does not contain what you think it does. You're passing the object directly to record.load()
. You'll almost certainly want to specifiy owner.id
or similar. Add a log.debug(JSON.stringify(data));
at the top of your post function so you can see what you're actually receivingKeir Kettle
11/22/2022, 1:02 PM{ "owner": "12345" }
CD
11/22/2022, 1:03 PMowner.owner
then ? unless i'm misunderstandingKeir Kettle
11/22/2022, 1:03 PMKeir Kettle
11/22/2022, 1:13 PMconst { owner } = data;
=== const owner = data.owner;
battk
11/22/2022, 1:28 PMbattk
11/22/2022, 1:29 PMbattk
11/22/2022, 1:30 PMerictgrubaugh
11/22/2022, 7:01 PMbattk
11/22/2022, 7:25 PMKeir Kettle
11/23/2022, 7:51 AMbattk
11/23/2022, 2:33 PM