Creating a GlideRecord and retrieving the current record

phugron
Mega Contributor

Hi everyone,

This may seem like a basic question to some of you, but I can't seem to get a handle on retrieving table information via GlideRecords. Mainly, I've been seeing different approaches to query a table (addQuery, RP.getParameterValue, if(!get('u_table_name', sys_id)), etc.). I've also looked into sysparam values and the wiki information has left me perplexed. Maybe I'm not looking in the right places for concise information, but any help would be welcomed.

On another related topic, I often find it useful to get the current values out of a table (ie. current.user, etc.) and am not sure how to go about it.

Any help is greatly appreciated (yes, I've read all SlightlyLoony's posts).

Regards,

phugron

3 REPLIES 3

Jace Benson
Mega Sage

If you're client side... this works great



var gr = new GlideRecord(g_form.getTableName());
gr.get(g_form.getUniqueValue());
//now you are on the current record using the object gr.


TJW2
Mega Guru

There are different methods to get a Record depending on what you are doing. I use:
var gr = new GlideRecord('table_name');
gr.addQuery('priority', '1'); // to get several records
gr.get('name', 'Test'); // if there is only one record you want to get


mduluk
Giga Expert

Here is an example we did to set some user values in a client script. u_requested_by is a reference variable to the sys_user table.

nction onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
//set phone and location to requester data
var caller = g_form.getReference('u_requested_by', setContact);


}

function setContact(caller){
g_form.setValue('location', caller.location);
g_form.setValue('u_contact_phone_number',caller.phone);
}