Notifications

27 views

Description

Script containing java script reserve words (like new, class etc ) throws error message "Javascript compiler exception: missing name after . operator" if not coded correctly

Below is the sample script which will throw the error "Javascript compiler exception: missing name after . operator" as the reserve word new is not coded correctly ( e.g. target.new)

 

var target = new GlideRecord('sys_history_line');
target.addQuery('sys_id','8f61af57dbf01010383521fb1396195e'); // sys_id from my OOB instance
target.query();
while (target.next()) {
gs.print("New: " + target.new);
}

Release or Environment

ALL

Cause

new, class etc which are reserved javascript words will have the issue if not properly coded in the script.

Resolution

You need to replace the value from target.new to target['new'] in the script and then the issue will be resolved.

Below is the sample script which will work successfully.

 

var target = new GlideRecord('sys_history_line');
target.addQuery('sys_id','8f61af57dbf01010383521fb1396195e');
target.query();
while (target.next()) {
gs.print("New Value is : " + target['new']);
}

Article Information

Last Updated:2020-05-21 05:10:34
Published:2020-05-21