GlideRecord - insertWithReferences()

Inserts a new record and also inserts or updates any related records with the information provided.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
String sys_id for the record inserted, or null if the record was not inserted.

If a reference value is not specified (as below), then a new user record is created with the provided first_name, last_name, and the caller_id value is set to this newly created sys_user record. The result is a new sys_user record with the provided first_name, last_name and a new incident record with the provided short_description and caller_id.

var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = 'New incident 1';
inc.caller_id.first_name = 'John';
inc.caller_id.last_name = 'Doe';
inc.insertWithReferences();
}

If a caller_id value is specified, then that caller_id is updated with the provided first_name, last_name. The result is a newly created incident record with values set for short_description and caller_id.

var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = 'New incident 1';
inc.caller_id.setDisplayValue('David Loo');
inc.caller_id.first_name = 'John';
inc.caller_id.last_name = 'Doe';
inc.insertWithReferences();
}