copy attachment from sys_attachment record to sc_task record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2017 10:11 PM
what's wrong in this code?
I am trying to attach file from sys_attachment to sc_task
below is the code:(Business rule)
table:sys_attachment
after insert
(function executeRule(current, previous /*null when async*/) {
var reqnumber;
var gr1;
var gr2;
var reqitemnumber;
var sysid;
var uv = current.getUniqueValue();
gs.addInfoMessage(uv);
var s1 = current.getValue('table_sys_id');
var gr = new GlideRecord('sc_request');
gr.addQuery('sys_id',s1);
gr.query();
if(gr.next()){
reqnumber = gr.getUniqueValue();
gs.addInfoMessage(reqnumber);
gr1 = new GlideRecord('sc_req_item');
gr1.addQuery('request',reqnumber);
gr1.query();
if(gr1.next()){
reqitemnumber = gr1.getUniqueValue();
gs.addInfoMessage(reqitemnumber);
gr2 = new GlideRecord('sc_task');
gr2.addQuery('request_item',reqitemnumber);
gr2.query();
while(gr2.next()){
sysid = gr2.getUniqueValue();
gs.addInfoMessage(sysid);
GlideSysAttachment.copy('sys_attachment', uv, 'sc_task', sysid);
}
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 11:10 AM
This seems to be issue with attachment API.
Please see below
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 11:14 AM
I believe you want to set your unique value (uv) to the sc_request, not the attachment itself. https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=c_GlideSysAttachmentScopedAPI
However, best practice would to not copy the attachment, but to make it visible on the task in a related list, as outlined in jim.coyne's post here: "Related Attachments" Related List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 10:14 PM
But If I do soo, if i click on the file it is getting downloaded but can we show it in a tab or (like manage attachments [view] link) instead of downloading the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2017 05:54 AM
You could create a UI Action (it would need to be a list context menu, to ensure it's running for a single attachment) that calls a UI page that mimics the UI macro they have out of box.
<!-- in some cases we want a "view" link to be displayed after the file name -->
<j:if test="${jvar_show_link}">
<j:choose>
<j:when test="${gs.getProperty('glide.ui.attachment_popup')=='false'}">
<a class="attachment" href="sys_attachment.do?sys_id=${sys_attachment.sys_id}&view=true"> ${gs.getMessage('[view]')}</a>
</j:when>
<j:otherwise>
<a class="attachment" click-on-enter="true" href="#" onclick="tearOffAttachment('${sys_attachment.sys_id}');">${gs.getMessage('[view]')}</a>
</j:otherwise>
</j:choose>
</j:if>