CAD · Question #185
Which of the following is the correct way to refer to a field in a GlideRecord query?
The correct answer is A. record.<field_name>. To access a field's value on a GlideRecord object, you use dot-walking notation with the GlideRecord variable name followed by the field's column name.
Question
Which of the following is the correct way to refer to a field in a GlideRecord query?
Options
- Arecord.<field_name>
- Bfield.<field_name>
- Cgr.<field_name>
- Dgr.get('<field_name>')
How the community answered
(64 responses)- A88% (56)
- B2% (1)
- C8% (5)
- D3% (2)
Why each option
To access a field's value on a GlideRecord object, you use dot-walking notation with the GlideRecord variable name followed by the field's column name.
After executing a query and retrieving a record using a GlideRecord object (e.g., `record`), its fields can be accessed directly using dot-walking notation (e.g., `record.field_name`).
"field.<field_name>" is not the correct syntax for accessing a field on a GlideRecord object; `field` is not a standard GlideRecord instance name.
While `gr.<field_name>` is a syntactically correct way to access a field if `gr` is the GlideRecord variable, `record.<field_name>` is also correct and often used as a general placeholder in documentation examples, making it the intended correct answer here.
`gr.get('<field_name>')` is a method that typically returns the display value or value of a specific field identified by a string, but the most direct and common way to access a field's value is using dot-walking directly, as in `record.field_name`.
Concept tested: GlideRecord field access syntax
Source: https://docs.servicenow.com/bundle/utah-application-development/page/app-store/dev_portal/API_reference/GlideRecord/concept/GlideRecordAPI.html
Topics
Community Discussion
No community discussion yet for this question.