gs.eventqueue does not work as expected from a scoped app executing from a business rule that contains a nested function (workaround)


When a scoped business rule contains a nested function and a call to a global script include is made that triggers the function gs.eventqueue the result is the arguments shifted one position to the right. This causes the sysevent record to be created incorrectly.

However, this works if debugging from the script debugger.


The cause is two parts. The first part is an issue with the platform's handling of the syntax around a nested function from within a scoped business rule when executed from an instance that does not have interpreted mode enabled. The second issue is that the script debugger always runs interpreted mode by designed which has no issue with the syntax of a nested function.

This is a known problem that ServiceNow has confirmed, however, at this time there are no plans to fix. The workaround/resolution would be a cut and copy of the nested function within the same business rule.


The workarounds is to avoid scoped business rules with nested functions and if one exist is to move the nested functions out from the parent function within the same business rule (cut and paste).

Move the nested function outside of the IIFE (the function wrapped in parentheses) example below.

The function thisWillBreak within this executeRule function will cause the fail.

(function executeRule(current, previous /*null when async*/) {

    //MORE CODE HERE the contains a call to thisWillBreak and a global script include that calls gs.eventqueue

function thisWillBreak() {};

})(current, previous);

Moving the function outside of the IIFE will allow this to function. Customers can also utilize script includes to encapsulate additional functionality.

(function executeRule(current, previous /*null when async*/) {


})(current, previous);

function thisWillWork() {};