I have a restlet trying to update a custom field o...
# suitescript
k
I have a restlet trying to update a custom field on an employee record - the code is literally:
const 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?
I’ve tried different employees, different fields - it seems I cannot update an employee?!?!
r
Check if your restlet is not trigerring other UE scripts deployed on the employee
k
Thanks for the reply - I’ve “undeployed” all the UE scripts against the employee record type (Customisation > Scripted Records - and unticked the “Deployed” box) - but the error persists …. 😧
c
Share the entire script, might be something in the define
k
Copy code
/**

* @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
    };
  });
c
owner
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 receiving
k
I’m trying this from Postman - data is passed as:
{ "owner": "12345" }
c
you want
owner.owner
then ? unless i'm misunderstanding
k
Also I assume if owner was null the error would point to that - I can retrieve the record and log it out - I just cant update it
no
const { owner } = data;
===
const owner = data.owner;
b
outside the reference error you get since success is not defined, your code looks fine
🙏 1
🤦 1
probably want to double check the scripts and workflows deployed to employees
you may also want to try using suitescript 2.0 instead
e
^ Curious why that might help
b
the error looks like its coming from an internal library and the internals of suitescript 2.0 is different from the internals of 2.1
👀 1
k
It was a good suggestion - and I redeployed the script as SS 2.x but the error remains 😪
b
2.x can be 2.0 or 2.1 depending on the account, its usually more sound to explicitly use 2.0