how to grab Request Item attachment ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2016 10:48 AM
Hey guys,
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',current.sys_id); // unable to find the current.sys_id
attachment.addQuery('table_name','sc_req_item');
attachment.query();
while(attachment.next()){
gs.addInfoMessage('inside attachment' + attachment.table_sys_id + ''+current.sys_id);
}
never gets into the while loop
sys_attachment table contains the information of the request table but for some reason i can not access it when the request is submited.
i am running the business rule after the request item is inserted.
when i use the rest api can find the attachment
https://########.service-now.com/api/now/attachment?table_sys_id=6d08141e0f302200d53d0dbce1050eaf
{
"result": [
{
"table_sys_id": "6d08141e0f302200d53d0dbce1050eaf",
"size_bytes": "3707",
"download_link": "https://dev10222.service-now.com/api/now/attachment/1808941e0f302200d53d0dbce1050e81/file",
"sys_updated_on": "2016-07-25 18:09:50",
"sys_id": "1808941e0f302200d53d0dbce1050e81",
"image_height": "4",
"sys_created_on": "2016-07-25 18:09:50",
"file_name": "Screen Shot 2016-07-21 at 8.00.27 AM.png",
"sys_created_by": "admin",
"compressed": "true",
"average_image_color": "#ebebeb",
"sys_updated_by": "admin",
"sys_tags": "",
"table_name": "sc_req_item",
"image_width": "2",
"sys_mod_count": "2",
"content_type": "image/png",
"size_compressed": "3599"
}
]
}
any help is really appreciated.
regards
NB
- Labels:
-
Personal Developer Instance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2016 11:01 AM
The table_sys_id field tells you what record in sc_req_item the file is attached to, not the sys_id of the sys_attachment record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2016 11:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2016 11:07 AM
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',current.sys_id); // unable to find the current.sys_id
attachment.addQuery('table_name','sc_req_item');
attachment.query();
running this query
is this wrong ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2016 11:09 AM
If this is from a business rule running on the sys_attachment table, then yes. You don't know which request item you are looking for.
What is it this business rule is supposed to be doing? If you run the business rule on the sc_req_item table, then the query becomes
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',current.sys_id);
attachment.addQuery('table_name', current.getTable());
attachment.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2016 11:16 AM
i am running a business rule on request item table ( sc_req_item) on insert
and trying to grab the attachment when the user raise a service catalog request
this query is running on same business rule.
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id',current.sys_id); // if i remove this statement it gets al the previous attachment records
attachment.addQuery('table_name', current.getTable());
attachment.query();