Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2018 02:14 PM
I also like gr.getValue(); because you can pass in a variable to set the field name, instead of a hard-coded string.
This is helpful when creating generic methods to search by fields dynamically when you do not necessarily know the field you want to search by ahead of time.
Example:
var SearchQueryUtil = Class.create();
SearchQueryUtil.prototype = {
initialize: function () {},
getValueByID: function (table, sys_id, field) {
var result_value = '';
var gr = new GlideRecord(table);
gr.addQuery('sys_id', sys_id);
gr.query();
if (gr.next()) {
result_value = gr.getValue(field);
}
return result_value;
},
type: 'SearchQueryUtil'
};