Dinesh Kumar11
Kilo Sage
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-10-2022 07:00 AM
Step 1:
Configure Below After Business Rule :
Table : sys_attachment
When : After and Insert
Filter condition :
Table Name is sc_task
Script :
(function executeRule(current, previous /*null when async*/) {
//GlideSysAttachment.copy('sc_task',current.sys_id , 'sc_req_item', current.request_item);
// Add your code here
var id = current.table_sys_id;
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', id);
gr.query();
if(gr.next()){
var ritm = gr.request_item;
var att = new GlideRecord('sys_attachment');
att.initialize();
att.file_name = current.file_name;
att.content_type = current.content_type;
att.compressed = current.compressed;
att.table_name = 'sc_req_item';
att.size_bytes = current.size_bytes;
att.size_compressed = current.size_compressed;
att.table_sys_id = ritm;
var attRec = att.insert();
var attDoc = new GlideRecord('sys_attachment_doc');
attDoc.addQuery('sys_attachment', current.sys_id);
attDoc.query();
while(attDoc.next()){
var attDocCopy = new GlideRecord('sys_attachment_doc');
attDocCopy.initialize();
attDocCopy.sys_attachment = attRec;
attDocCopy.position = attDoc.position;
attDocCopy.length = attDoc.length;
attDocCopy.data = attDoc.data;
attDocCopy.insert();
}
}
})(current, previous);
Hope you will find it as helpful. Don’t forget to Mark it Helpful and Bookmark article so you can easily find on your profile.
Thank you,
Dinesh Kumar Raghu,
Capgemini India Pvt Ltd.
GmailID : dineshkumar.raghu9426@gmail.com
Labels:
- 2,888 Views
Comments
Bob Glasser
Tera Contributor
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
02-02-2023
09:43 AM
This just saved me. Thank you!
Kishor O
Tera Sage
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
07-29-2023
10:16 AM
Hi @Dinesh Kumar11 ,
Can u tell me why you have copied attachment to both sys_attachment and sys_attachment_doc table.
What is the use of sys_attachment_doc table in servicenow.
I am not understanding the use of below lines of code
var attDoc = new GlideRecord('sys_attachment_doc'); attDoc.addQuery('sys_attachment', current.sys_id); attDoc.query(); while(attDoc.next()){ var attDocCopy = new GlideRecord('sys_attachment_doc'); attDocCopy.initialize(); attDocCopy.sys_attachment = attRec; attDocCopy.position = attDoc.position; attDocCopy.length = attDoc.length; attDocCopy.data = attDoc.data; attDocCopy.insert(); }