GlideRecord updateWithReferences and insertWithReferences
Update a record and referenced fields in one operation.
Sometimes you want to update referenced fields while saving the base record.
- Related records are updated first, then the base record.
- If a related record does not exist, one can be created.
- If you need to set the value of a reference field on the base record, set it using
setDisplayValue()before manipulating referenced record fields.
updateWithReferences()
var inc = new GlideRecord('incident');
inc.get(sys_id); //Get incident record based on the sys_id
inc.caller_id.first_name = 'Jesper';
inc.caller_id.email = 'jesper@not-a-real-email.com';
inc.updateWithReferences();
insertWithReferences()
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = 'My printer is broken';
inc.caller_id.setDisplayValue('Jesper Testuser'); //Without this, a new user could be created
inc.caller_id.first_name = 'Jesper';
inc.caller_id.email = 'jesper@not-a-real-email.com';
inc.insertWithReferences();