The CreatorCon Call for Content is officially open! Get started here.

Can't GlideQuery sys_attachment table?

e_wilber
Tera Guru

I am not sure what's going on.  I have queried the attachment table in the past but for some reason my client script below doesn't work.

My first alert does show the sys_id but the 2nd test alert doesn't show up at all. I have tracked this down to the query I am doing on the attachment table. When all three query lines are commented, both alerts work. When the first one is active, I only get the first popup.

Any idea what's going on?

function onLoad() {
alert(g_form.getUniqueValue());

var att = new GlideRecord('sys_attachment');
//attachment.addQuery('table_sys_id', g_form.getUniqueValue());
//attachment.query();
alert('2');

}

4 REPLIES 4

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

You should not use glideRecord client side.  If you do you should use a callback

 

In your script the var name should not be attribute, but att, as that is how you declared it

vinothkumar
Tera Guru

I have tried in incident form by glidequerying the attachment table. It is working after couple of seconds when the attachment was added. What is your usecase in putting in OnLoad client script for new record.

 

Try put in onChange, it will work

Jim Coyne
Kilo Patron

As mentioned by Arnoud, using GlideRecord client-side is not a good practice.  Depending on what you are doing, a Display Business Rule which populates a scratchpad variable would be better.  All depends what you are actually trying to do.

However, the issue is you are causing a runtime error because you declare a variable called "att" but then use "attachment.addQuery".  Try using "att.addQuery" instead.

Rahul Priyadars
Tera Sage

Glide Record at Client Side - This is why you are getting Issues. It Should be used at Server Side scripts.

 

Glide Ajax /Display BR will be another way of doing this.

Some good blog on this:

http://www.snc-blog.com/2012/07/18/client-scripting-gliderecord-query-using-a-callback-function/

Regards

RP