
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 06:40 AM
We have several requests where users must attach an excel or word document before submitting the item. I tied to add the ticket attachment widget to the Approval form but it does not show any attachments. I'm guessing this had to do with the approval form being on the sys_approval table and the attachment is on the sc_req_item table. What code would need to be updated to if I were to clone the attachment widget to pull the attachment associated with the approval for from the sys_approval table?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 06:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2018 03:13 PM
For what its worth, its possible to update the approval record widget to display the attachments.
Widget HTML Template:
<div ng-if="!data.isValid">
${Record not found}
</div>
<div ng-if="data.isValid">
<div class="panel panel-{{::options.color}} b">
<div class="panel-heading">
<h4 class="panel-title">${Approval request for {{::task.table}} {{::task.number.display_value}}}</h4>
</div>
<div class="panel-body">
<div ng-if="task.attachments.length > 0">
<label>${Attachments}:</label>
<ul>
<div ng-repeat="attachment in task.attachments">
<a target="_blank" href="/sys_attachment.do?view=true&sys_id={{attachment.sys_id}}">
<img ng-if="attachment.thumbnail_path" alt="" ng-src="/{{attachment.path}}?t=medium" class="img-responsive"/>
</a>
<div>
<li><a href="/sys_attachment.do?sys_id={{attachment.sys_id}}" target="_blank"><strong>{{attachment.file_name}}</strong></a> {{attachment.size}}</li>
</div>
</div>
</ul>
</div>
<div ng-if="data.items.length > 0">
<h3><u>${Items in this Request}</u></h3>
<div ng-repeat="item in data.items">
<h4><a ng-href="?id=ticket&table=sc_req_item&sys_id={{::item.sys_id}}&view=sp">
{{::item.short_description}}
</a>
</h4>
<div ng-if="item.attachments.length > 0">
<label>${Attachments}:</label>
<ul>
<div ng-repeat="attachment in item.attachments">
<a target="_blank" href="/sys_attachment.do?view=true&sys_id={{attachment.sys_id}}">
<img ng-if="attachment.thumbnail_path" alt="" ng-src="/{{attachment.path}}?t=medium" class="img-responsive"/>
</a>
<div>
<li><a href="/sys_attachment.do?sys_id={{attachment.sys_id}}" target="_blank"><strong>{{attachment.file_name}}</strong></a> {{attachment.size}}</li>
</div>
</div>
</ul>
</div>
</div>
</div>
</div>
</div>
<sp-widget widget="data.ticketConversation" />
</div>
Server Script:
// g_approval_form_request is for approval summarizer ACLs
// that let user read a record they need to approve. This global
// variable is then deleted at the bottom of the script
g_approval_form_request = true;
var gr = $sp.getRecord();
if (gr == null || !gr.isValid()) {
data.isValid = false;
//return;
}
if (gr.getValue("approver") != gs.getUserID())
data.approver = gr.approver.getDisplayValue();
data.isValid = true;
var task = getRecordBeingApproved(gr);
var t = {};
t = $sp.getFieldsObject(task, 'number,short_description,opened_by,requested_by,start_date,end_date,price,recurring_price,recurring_frequency,requested_for,sys_class_name,request,quantity,cat_item,special_instructions,sys_id,request');
t.table = task.getLabel();
........
//Get attachments for current record being approved
t.attachments = getAttachments(t.sys_class_name.value, t.sys_id.value);
var items = [];
var idx = 0;
var itemsGR = new GlideRecord("sc_req_item");
itemsGR.addQuery("request", task.sys_id);
itemsGR.query();
while (itemsGR.next()) {
var item = {};
//Get attachments for requested items within parent request
item.attachments = getAttachments("sc_req_item", itemsGR.getValue("sys_id"));
..............
function getAttachments(tablename, sysid) {
var attachments = [];
var stream = $sp.getStream(tablename, sysid);
for(var i = 0; i < stream.entries.length; i++){
var curEntry = stream.entries[i];
if(curEntry.element == 'attachment'){
attachments.push(curEntry.attachment);
}
}
return attachments;
}
..........
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2018 01:24 PM
This is great and exactly what i was looking for, however it is very difficult to know where in the Server Script you are inserting or overwriting.
The ....... is a bit vague.
Any way to clearify?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2021 09:59 AM
Hi
Could you please update the link? I have the same question and the link is no longer valid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2021 09:56 AM
Its been awhile and I no longer work for the company I set this up at but I believe the wiki article was for GlideSysAttachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 07:22 AM
I am doing the same thing for all sc_tasks to inherit from their parent RITM. I am sure you can create a clone of the attachment and assign it to the Approval record but if possible it seems like the best option would to add these to a defined related list.
https://www.servicenowguru.com/system-definition/relationships/defined-related-lists/