How to automatically add RITM attachments into SCTASK?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2020 10:37 AM
We are being asked to include the RITM attachments into the Catalog Tasks automatically. Can you share the steps or script?
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2020 10:39 AM
try this:
Create After business rule on "sys_attachment" table, operation would be "INSERT", use the business rule condition Table Name | IS | sc_req_item table.
copyAttachments(current);
function copyAttachments(attachment) {
var tasks = new GlideRecord("sc_task");
tasks.addActiveQuery();
tasks.addQuery('request_item', current.table_sys_id);
tasks.query();
while(tasks.next()) {
gs.log('Copying attachment for task ' + tasks.number, 'ServiceNow Community');
var gsa = new GlideSysAttachment();
gsa.copy(current.table_name, current.table_sys_id, tasks.getTableName(), tasks.sys_id);
}
}
//The above one will work otheriwse this one also works
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
if (!gr.hasNext())
{
GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);
}
})(current, previous);​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2020 11:53 AM
ServiceNow recommends not copying attachments for a number of reasons - database bloat, out of sync attachment updates, and timing/coverage (you would need to run business rules on the sys_attachment table AND sc_task to be sure attachments are shown as each new task and attachment gets created).
Instead you can simply show the RITM attachments on the Catalog Task as a related list.
- Navigate to System Definition -> Relationships.
- Click the New button to create what will become a new related list.
- Type a Name - whatever you want to appear on the Related List/tab. Applies to table sc_task. Queries from table sys_attachment. The Query with script will look like this
(function refineQuery(current, parent) { current.addQuery('table_sys_id' , parent.request_item); })(current, parent);
- When viewing a Catalog Task record, right-click the header and choose Configure > Related Lists.
- Select the Name you created in step 3 so that it appears in the Selected box.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2020 06:20 AM
Were you able to test this solution for your requirements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-09-2020 07:08 AM
Thanks
Also added this as related list in Workspace view.
Chris