
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 08:24 AM
var gr = new GlideRecord('incident');
gr.addQuery('active', 'true');
gr.query();
if (gr.next())
{
// This way ?
gr.sys_id;
// Or this way ?
gr.getValue('sys_id');
}
Which is safest/best method to get the value? Dotwalk the gr object or use the built-in method, getValue() ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 09:01 AM
I prefer gr.getValue('sys_id');
gr is a pointer. If you pop the sys_ids in to an array, you get a list of all of the same values (of the last record.) getValue() copies the value rather than using the reference.
getValue() has saved my life more times than I care to admit. While it's not perfect, it's often the better option to ensure you have the value (especially in loops.)
As a general rule, getters/setters are a better way to go in object oriented programming.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 09:01 AM
I prefer gr.getValue('sys_id');
gr is a pointer. If you pop the sys_ids in to an array, you get a list of all of the same values (of the last record.) getValue() copies the value rather than using the reference.
getValue() has saved my life more times than I care to admit. While it's not perfect, it's often the better option to ensure you have the value (especially in loops.)
As a general rule, getters/setters are a better way to go in object oriented programming.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 09:21 AM
I concur with your opinion and suggestion. Thank you for taking the time to explain.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 11:24 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2016 12:28 PM
He he. It backs up what I said because I wrote them both. 🙂