Copy Attachment with out duplicates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2014 06:45 AM
Hi All,
I am trying to copy attachment from task table to request with out duplicates
can any one help me
thanks in advance
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2014 07:01 AM
Hi Nayeem,
What do you mean by without duplicates? I you want to copy attachments from record to record, you can use this in any server side script:-
GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');
Thanks & Regards,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 09:28 PM
Hi Hari,
Actual scenario is when I attach a attachment to request I am able to copy the attachment to task but if I attach other attachment to request both previous one and current attachments both are copying so that in task I am getting one attachment two times can you please help me
Thanks & Regards
Nayeem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2014 09:41 PM
You can use the below code inside an after insert business rule on the sys_attachment table to remove duplicates:-
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'LIKE', '<your table name>'); //substitute your table name here
gr.orderBy('table_sys_id');
gr.orderByDesc('sys_created_on');
gr.query();
var lastID = 'not_a_match';
var lastFile = 'not_a_match';
while (gr.next()) {
var isDuplicate = (lastID == gr.table_sys_id) && (lastFile == gr.file_name);
lastID = gr.table_sys_id;
lastFile = gr.file_name;
gs.print(gr.table_sys_id + ' ' + gr.table_name + ' ' + gr.file_name + ' ' + gr.sys_created_on + ' ' + isDuplicate);
if (isDuplicate)
gr.deleteRecord();
}
Thanks & Regads,
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2015 08:24 AM
How does ServiceNow handle the data attachments? If it knows one's been copied from the Catalog Task to the Approval or RITM (by use of the GlideSysAttachment.copy()), does it actually keep that many copies of the same attachment or does it just modify the linkages to give access to that same file in multiple ways?