GlideForm - getReference(String fieldName, Function callBack)

Returns the GlideRecord for a specified field.

If a callback function is present, this routine runs asynchronously, and browser (and script) processing will continue normally until the server returns the reference value, at which time the callback function will be invoked. If a callback function is not present, this routine runs synchronously and processing will halt (causing the browser to appear to hang) while waiting on a server response.

Important: It is strongly recommended that a callback function be used.

Callback function support for ServiceCatalogForm.getReference is available.

Note: This requires a call to the server so using this function will require additional time and may introduce latency to your page. Use with caution. See Avoid Server Lookups.
Table 1. Parameters
Name Type Description
fieldName String Name of the field.
callBack Function Name of the call back function.
Table 2. Returns
Type Description
GlideRecord The GlideRecord object for the specified field. If the specified reference cannot be found, then it returns an initialized GlideRecord object where currentRow = -1 and rows.length = 0.

function onChange(control, oldValue, newValue, isLoading) {
   var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed into callback as first arguments
  if (caller.vip == 'true')
    alert('Caller is a VIP!');
}