How to read a field whose name is a reserved word (new)? I

risanchez
Giga Expert

I need to read a value from a table whose one of the columns is a reserved word   - new, but when I try to do this, I get a Javascript error:

This is a snipped of my script:

while(gr.next()) {

      description +=   gr.new+'\r\n';

}

But I get Warning when I click on the "verify syntax" button and since this is jut a Warning, I ignore it, save the script and let it run, but when it runs, it throws the following exception:

Execption in Activity Handler:Log Object

Object

lineNumber: string = 52

sourceName: string = <refname>#17(eval)

name: string = SyntaxError

message: string = missing name after . operator

1 ACCEPTED SOLUTION

Aric3
Giga Expert

Hi Ricardo,



You can either use the GlideRecord methods getValue or getDisplayValue depending on the field type.



Using the getValue method, your example code would become:


while (gr.next()) {
  description += gr.getValue('new') + '\r\n';
}


View solution in original post

3 REPLIES 3

Mike Allen
Mega Sage

I think it is _new.   So, gr._new.


Aric3
Giga Expert

Hi Ricardo,



You can either use the GlideRecord methods getValue or getDisplayValue depending on the field type.



Using the getValue method, your example code would become:


while (gr.next()) {
  description += gr.getValue('new') + '\r\n';
}


Rogers Cadenhe1
Giga Guru

When a field name is a reserved word in JavaScript, use bracket notation instead of dot walking to reference it. Change the statement inside the while loop to this:

description +=   gr['new']+'\r\n';