copy attachments from request to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2016 11:46 PM
Hi,
I have a requirement to copy all the attachments from Request to the corresponding RITMs.
I have written an After-Insert Business rule on the Request table to achieve the same. But it seems the code is not working as expected.
Name: Copy Attachments to RITM
Table: Request (sc_request)
When to run: After - Insert
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', current.sys_id);
ritm.query();
while(ritm.next())
{
GlideSysAttachment.copy('sc_request', current.sys_id, 'sc_req_item', ritm.sys_id);
}
})(current, previous);
Any lead will be appreciated. Thanks in advance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 01:41 AM
Hi randrews,
I have already created a related list on the REQ form which shows the attachment on the RITM, the problem with this is that it is not shown in the portal. I need to be able to have end-users who do not have roles view the attachments on approvals in the portal as they do not use the console.
Any assistance would be greatly appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-27-2018 12:45 PM
You can use a display Business Rule as well. This will add links to the attachments to the header of the form:
Condition:
!RP.isPopup() && current.request.getRefRecord().hasAttachments()
Script:
(function executeRule(current, previous /*null when async*/) {
var link = '';
var fileName = '';
var count = 0;
var fullResult = '';
var att = new GlideRecord('sys_attachment');
att.addQuery('table_name','sc_request');
att.addQuery('table_sys_id',current.request);
att.query();
while(att.next()){
if(count > 0){
fullResult += '<br/>';
}
link = 'sys_attachment.do?sys_id=' + att.sys_id;
fileName = att.file_name;
fullResult += '<a href="' + link + '">' + fileName + '</a>';
count++;
}
if(link != ''){
gs.addInfoMessage("<b>Request's Attachments:</b><br/>" + fullResult);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 02:55 AM
Hi Benn23,
Thanks for your response. Could you please break down the condition for me? I understand the second half, checking to see whether the request has attachments or not. But what does 'RP.isPopup()' check?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 06:21 AM
!RP.isPopup() prevents the script from running when a record is viewed via the hover over pop-up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2018 07:50 AM
I have tried adding the business rule but I am not seeing the desired result of copying the attachment over from the RITM to the REQ.
I have it as a Display rule running on the 'Request [sc_request]' table, as this is the ticket without the attachment.
and I have amended the line 'att.addQuery('table_name',sc_request'); to 'att.addQuery('table_name',sc_req_item'); as this is where the attachment is added to after submitting the request.
Is this correct?