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


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


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

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


var gr = GlideRecord("sys_user");

This is a malformed statement.


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>");


var gr = new GlideRecord("sys_user");

Additional Information