
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2015 04:21 AM
I'm a bit baffled as to where the code-behind is for the attachment ui page when initiated.
I found the Script Include, "AttachmentAjax", that handles the actual updating and processing of an attachment. I've scoured through and tested each function of the Client Script section of the attachment UI page, but I just don't see where the call is to first query the sys_attachment table.
Visual Example:
I have a link on a UI page:
The link calls this function:
The "attachment" UI Page came built in with ServiceNow (Eureka). Like I've mentioned though, I've gone over the attachment ui page line by line and I don't see any ajax calls or any functions that, upon loading, go and get current attachments, but it does. Where is this code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2015 08:10 PM
Hi David,
Far down in the code you will find a line like this:
<g2:attachment_list sys_id="${jvar_target_sys_id}" table="${jvar_target_table}">
That calls an extension to Jelly which takes as input the sys_id and table of the record that you're on when you open the dialog. It calls new SysAttachment();
sa.getAttachments(table, sys_id);
That gets Attachments for all of the records for that given table, and puts it into a variable that is used in the next line of that page:
<g2:for_each_record file_variable="sys_attachment" var="attachment">
This loops over all of those attachments and outputs the HTML you see below *that*- an input button, and then a UI Macro (attachment_entry).
I hope that's helpful
Cory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2015 08:10 PM
Hi David,
Far down in the code you will find a line like this:
<g2:attachment_list sys_id="${jvar_target_sys_id}" table="${jvar_target_table}">
That calls an extension to Jelly which takes as input the sys_id and table of the record that you're on when you open the dialog. It calls new SysAttachment();
sa.getAttachments(table, sys_id);
That gets Attachments for all of the records for that given table, and puts it into a variable that is used in the next line of that page:
<g2:for_each_record file_variable="sys_attachment" var="attachment">
This loops over all of those attachments and outputs the HTML you see below *that*- an input button, and then a UI Macro (attachment_entry).
I hope that's helpful
Cory

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 04:23 AM
Yes, I did notice this too yesterday, but I thank you for this response. I now wonder how to further filter that call. For instance, I'm passing a " file_name " to the attachment ui pop-up that I want to query against.
This, however crashes the UI:
<j:set var="jvar_target_floorMap_fileName" value="${RP.getWindowProperties().get('target_floorMap_fileName')}" />
<g2:attachment_list sys_id="${jvar_target_sys_id}" table="${jvar_target_table}" file_name="${jvar_target_floorMap_fileName}">
It's the file_name="${jvar_target_floorMap_fileName}" that's breaking it.
Question... how can I add query parameters to this for a more refined lookup? Granted, I really need to take an advanced scripting course from ServiceNow for Jelly, but since we're moving from Eureka to Geneva after this new year, I'm ditching as much Jelly as I can for Angular.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 10:54 AM
Hi David,
You cannot pass parameters to the attachment_list function that it's not already set up to use. That call takes exactly two parameters: table, sys_id. That is all it can accept.
If you want a special query for sys_attachment, then you would have to write your own. Unfortunately, there is a lot in that little g2:attachment_list which I glossed over. In addition to doing the query, it has a few other jelly templates which get invoked along the way, which contribute to the outputted HTML. It's not a simple process- you can't just modify the query, you have to replace everything that goes along with generating this output.
To fully replace the out-of-box functionality would require some advanced scripting, knowledge of Jelly, and a lot of effort. It's possible, but you would probably be best served contracting the work out to one of our partners, or to one of the professional/expert services teams who have the expertise in scripting, jelly, and implementations to pull it off.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2015 11:48 AM
Thanks for your reply and thoughts on the matter.