Best Practices for GlideRecord Data AccessOverview: This article defines the critical differences between direct dot-walking (gr.field_name) and the .getValue() method when interacting with GlideRecord objects. Selecting the incorrect method can lead to "pointer bugs" where variables unexpectedly update to the last record processed or significant performance degradation in high-volume scripts. Use this guide to ensure data integrity and memory efficiency in your server-side scripting. 1. When to use .getValue() Use .getValue() when you need the raw database value (usually a string) rather than the field object. Accessing Sys_IDs: Always use .getValue('field_name') for reference fields.Variable Assignment: Ensures the variable is "locked" to a string value.Inside Loops: More memory-efficient as it avoids creating new GlideElement objects for every iteration. Example: The "Pointer Trap" in Arrays If you push a direct field reference into an array inside a loop, you are pushing a pointer to the object. var gr = new GlideRecord('incident');gr.addActiveQuery();gr.setLimit(3);gr.query();var incidentList = [];while (gr.next()) { // WRONG: incidentList.push(gr.number); // This results in: [INC003, INC003, INC003] // CORRECT: Extract the string value incidentList.push(gr.getValue('number')); // This results in: [INC001, INC002, INC003]} 2. When to use Dot-walking Use direct dot-walking when you need to access metadata, display values, or related tables. Example: Metadata and Related Tables var gr = new GlideRecord('incident');gr.get('sys_id_here');// 1. Check field-level securityif (gr.short_description.canWrite()) { // Logic here}// 2. Reach across tables (Incident -> Caller -> Email)var callerEmail = gr.caller_id.email;// 3. Get human-readable display valuesvar status = gr.state.getDisplayValue(); 3. The "Object Pointer" Warning A common mistake is assigning a reference field to a variable without casting it to a string. Example: Unexpected Variable Changes var gr = new GlideRecord('incident');gr.query();if (gr.next()) { var firstIncident = gr.number; // Reference pointer gs.print("First: " + firstIncident); // Output: INC001 gr.next(); // Move to next record gs.print("First: " + firstIncident); // Output: INC002 (The pointer updated!)}// THE FIX:var firstIncident = gr.getValue('number'); Summary of Guidelines: TaskRecommended MethodReasonStoring in Arrays.getValue('field')Prevents data corruption; ensures unique values.Reading Sys_IDs.getValue('field')Returns a primitive string; avoids reference pointer issues.Checking Permissionsgr.field.canRead()Required for accessing the GlideElement metadata API.Performance.getValue()Minimizes memory overhead by avoiding object creation.Display Labelsgr.field.getDisplayValue()Required to trigger the engine's display label logic.