- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2016 12:45 PM
I want to make sure that attachments from a request item are visible on tasks.
I know I can easily copy them to the tasks, but unnecessary duplication and synchronizing issues make this less desirable.
I could display an info message with a link to any attachments. (this might be the next best thing)
What I would really like to do is modify the attachment macro to include the RITM attachments along with any sc_task attachments so that whoever is working a task will have visibility to any attachments the requester may have placed on it.
Anyone done this before? (Or have a better idea)
Thanks,
-Stephen
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2016 12:23 AM
Today is your lucky day... "Consolidated Attachments" is actually something I've been working on lately, using a defined Relationship as Anthony suggests.
Here is a defined relationship you can create for the [task] table that will show you attachments for ALL references (including parent, request, requested_item, parent_incident, etc.), as well as from any emails on the current record AND all the references just mentioned. One nice thing is that the related list will also give you a nice label telling you which object the attachment comes from. To do so:
- Go to System Definition>Relationships and create New
- Set Applies to table: Task [task]
- Set Queries from table: Attachment [sys_attachment]
- For the "Query with" script, enter the following:
try{
var itemList = getItemList();
//Get attachments for all of the above
current.addQuery('table_sys_idIN' + itemList);
}
catch(e){
gs.log("Error(" + e.lineNumber + "): " + e, "CONSOLIDATED ATTACHMENTS");
}
function getItemList(){
var arrItems=[],references=[],relTasks=[],relEmails=[];
relTasks=[parent.sys_id];
//Get References
references = getReferences(parent);
//Get Emails
var instanceList = relTasks.concat(references);
relEmails = getRelatedEmails(instanceList.join());
arrItems = instanceList.concat(relEmails);
return arrItems.join(); //Return as a CSV list
}
function getReferences(parent){
//Get referenced record_ids
var refFields = parent.getFields();
var itemListRefs = [];
for (var i=0; i<refFields.size(); i++) {
var field = refFields.get(i);
var ed = field.getED();
if(field.getED().getInternalType() == 'reference' && field.hasValue()){
itemListRefs.push(field.toString());
}
}
return itemListRefs;
}
function getRelatedEmails(instanceList){
var strItems = '';
var grRelEmail = new GlideRecord('sys_email');
grRelEmail.addQuery('instanceIN' + instanceList);
grRelEmail.query();
while(grRelEmail.next()){
strItems += grRelEmail.sys_id + ',';
}
return strItems.split(',');
}
After you've created this defined relationship, just go to Configure->Related Lists to add it to your form (to avoid redundancies, I would remove the standard "Attachments" related list for recundancy's sake).
This is actually a trimmed-down version of what I've been working on... the full version includes attachments from all records that reference the current record as well (i.e., those that appear on its related lists). But I'm still working on the efficiencies of that method, so haven't included it here. The thing that makes it work nicely is that attachments rely on a document ID field... so you only need to use the item list of sys_ids to find all related attachments, and forget about what table they belong to.
Enjoy,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 01:13 PM
I'm trying this solution now - I'm hopeful it will solve my problem.
By the way... I have to ask, was this--"(to avoid redundancies, I would remove the standard "Attachments" related list for recundancy's sake)"--intentionally redundant? Very sneakily hilarious if so.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 01:20 PM
So I applied your solution, then went to add the new Related List to the sc_task form view, and realized there was already an "All Attachments" related list that showed the attachment from the parent sc_req_item record.
Maybe they made this a baseline feature? I'm on Kingston and didn't need to set anything new up (at least not to see sc_req_item attachments in sc_task child records).
Thanks though - this helped me find the solution I needed anyway.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2018 08:13 AM
It's possible they've added it as a base feature. I checked in my developer instance (currently running Jakarta) and didn't see it, but they may have added it since in a newer version. No mention found on docs.
Thanks,
-Brian

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2018 08:04 AM
Yes... I was always a fan of the Department of Redundancies department.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2019 06:47 AM
Brian,
I used this solution and it works great. However after using it a few weeks I noticed the profile photos of the Opened By and Caller/Requested by are in the related attachment tab. I cannot figure out why. Have you seen this?