Copy Attachment with out duplicates

nayeem2
Giga Expert

Hi All,

 

I am trying to copy attachment from task table to request with out duplicates

 

can any one help me

 

thanks in advance

35 REPLIES 35

ROFL!



Nice job, and you used an IIFE!   Elegance meter maxed!



I won't comment on the rest though....  


randrews
Tera Guru

i did something a little different.. in that i did not want duplicate attachments everywhere....   you could actually create one for the sc_task table and add one more layer of .parent to show the attachments on the request on all the tasks.




so... i created a global relationship to show attachments on an items parent...



NAME:   Parent --> Attachment


applies to table                   Global


Queries from Table                   Attachment


query with:



current.addQuery('table_name',parent.parent.sys_class_name);


current.addQuery('table_sys_id',parent.parent.sys_id);


Yeah Raymond, the above "Related Attachments" thing I posted on Aug 5th, 2015 shows from child to parent, grandparent... or from parent up AND down, as well as across to see all the siblings and sibling's children.   It just takes a little training to look down on the Related Attachment tab instead of up at the top where attachments for only that record is.


peterraeves
Mega Guru

The easiest way to do this is to use the GlideSysAttachment API



If you have a unidirectional sync, you could use


//GSA functions


var gsa = new GlideSysAttachment();


gsa.deleteAll(targetGR);


gsa.copy(current.getTableName(), current.getValue('sys_id'), targetTable, targetID)


I don't know how your tables are built, so you need to figure out yourself, how you will retrieve the target gliderecord, table and id, but aside from that, the above 3 lines, will correctly transfer the attachments, by first cleaning the destination and refilling it with your up-to-date attachments.


Yes, see above for a design for "Related Attachments" that looks up/down parent-child and across to sibling tasks.   You should be able to do a variation whenever there is some kind of relationship where you need to see attachments between the two.