Accessing Field Information From GlideRecord

I made an accidental discovery a few days ago. I searched the wiki and couldn’t see any documentation around it. It turns out every field returned in a GlideRecord also comes with a property that contains all the dictionary values.

Why is this useful? For around 99% of the time it’s not and you can pretend it’s not there. For me, I have been writing functionality that automatically checks all scripts in the system that they have adhered to a particular rule set. To do this, I needed to know if a table had any scripting fields on there. Initially I was doing a GlideRecord on the sys_dictionary table searching for the details. However, with this route, no database query was required anymore.

To access the data, you can start by initializing a new GlideRecord:

var gr = new GlideRecord('incident');

Now you have the GlideRecord available, you can now access the dictionary definition of all the fields. For example, if you want to print out if the caller_id field is mandatory from the dictionary, you just use:

gs.print( gr.caller_id.sys_meta.mandatory );

The sys_meta property is automatically returned with every GlideElement within the GlideRecord. To see all available options within the sys_meta object, use the following:

for (key in gr.caller_id.sys_meta) {
gs.print("Key: " + key + ". Value: " + gr.caller_id.sys_meta[k]);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.