Error message "Cannot read property 'apply' of undefined"


Description

A custom UI Action is not working as expected. When the UI Action is script is executed, this error is shown in the browser console: Uncaught TypeError: Cannot read property 'apply' of undefined

Cause

This occurs when you have the following statement in your code:

var gr = GlideRecord("<tablename>");

eg.

var gr = GlideRecord("sys_user");

This is a malformed statement.

Resolution

It is necessary to use the new operator to create an instance of the GlideRecord before it can be used successfully from custom scripts.

Modify the statement to use the new operator:

var gr = new GlideRecord("<tablename>");

eg.

var gr = new GlideRecord("sys_user");

Additional Information