in servicenow, .without GetReference Any idea without using GetReference to print Caller…
- User
in servicenow, .without GetReference
Any idea without using GetReference to print Caller Manager,Location,Department.
- Assistant
in servicenow, .without GetReference
Any idea without using GetReference to print Caller Manager,Location,Department.
In ServiceNow, typically to get fields from a referenced record (like the Manager, Location, Department on the Caller), you'd use getReference() method in scripts (server-side) or GlideRecord queries.
If you want to get these values without using getReference(), you basically need to access the fields directly if they are already on the current record or perform a GlideRecord query yourself.
Assuming caller_id is a reference field on the current record (e.g. Incident), and you want to get the Manager, Location, Department fields from sys_user (caller), without using getReference.
getReference()sys_userInstead of getReference(), you can do a GlideRecord query on the sys_user table for the caller_id, then get the fields:
var callerGR = new GlideRecord('sys_user');
if (callerGR.get(current.caller_id)) {
var manager = callerGR.manager.getDisplayValue(); // Caller’s Manager (reference field to sys_user)
var location = callerGR.location.getDisplayValue(); // Caller’s Location (reference to cmn_location)
var department = callerGR.department.getDisplayValue(); // Caller’s Department (reference to cmn_department)
gs.info('Manager: ' + manager);
gs.info('Location: ' + location);
gs.info('Department: ' + department);
}
This effectively does the same thing as getReference() but explicitly queries the referenced user record.
If you want to avoid any queries:
current.caller_id.manager.name) does NOT load referenced record data without getReference or GlideRecord.Since that’s the case, you cannot directly access referenced fields' properties without querying that referenced record.
getReference().getReference() is just a shortcut for implicitly querying the reference record.If you want a code snippet to print Caller Manager, Location and Department without getReference():
var callerSysId = current.caller_id;
if (callerSysId) {
var gr = new GlideRecord('sys_user');
if(gr.get(callerSysId)) {
gs.info('Manager: ' + gr.manager.getDisplayValue());
gs.info('Location: ' + gr.location.getDisplayValue());
gs.info('Department: ' + gr.department.getDisplayValue());
}
}
If you need a client-side (GlideAjax) approach, let me know!
Not yet included in a published release.