Copy an attachment from RITM to Sc Task and Vice Versa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:02 AM
I have a requirement which should automatically attach an attachment to all sc tasks of an ritm and vice versa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:06 AM
Hello @Sharan Ellendul
Plz go through the Below link :-
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 03:08 AM - edited 07-24-2023 03:10 AM
Hi @Sharan Ellendul ,
Please find the below script which will help you...
Copy RITM Attachments to task
(function executeRule(current, previous /*null when async*/ ) {
var flag = 0;
var reqtask1 = new GlideRecord('sc_task');
reqtask1.addQuery('request_item', current.table_sys_id);
reqtask1.query();
while (reqtask1.next()) {
var canAttach = new GlideRecord('sys_attachment');
canAttach.addEncodedQuery('UPDATE_QUERY_HERE');
canAttach.query();
if (canAttach.next()) {
flag = 1;
}
}
if (flag == 0) {
var reqtask = new GlideRecord('sc_task');
reqtask.addQuery('request_item', current.table_sys_id);
reqtask.query();
while (reqtask.next()) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', reqtask.sys_id);
att.query();
while (att.next()) {
att.deleteRecord();
}
GlideSysAttachment.copy('sc_req_item', current.table_sys_id, 'sc_task', reqtask.sys_id);
}
}
})(current, previous);
Copy Task Attachments to RITM
(function executeRule(current, previous /*null when async*/ ) {
var flag = 0;
var reqItem1 = new GlideRecord('sc_task');
if (reqItem1.get(current.table_sys_id)) {
var canAttach = new GlideRecord('sys_attachment');
canAttach.addEncodedQuery('UPDATE_QUERY_HERE');
canAttach.query();
if (canAttach.next()) {
flag = 1;
}
}
if (flag == 0) {
var reqItem = new GlideRecord('sc_task');
if (reqItem.get(current.table_sys_id)) {
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', reqItem.request_item.sys_id);
att.query();
while (att.next()) {
att.deleteRecord();
}
GlideSysAttachment.copy('sc_task', current.table_sys_id, 'sc_req_item', reqItem.request_item.sys_id);
//att.setWorkflow(false);
}
}
})(current, previous);
I HOPE IT HELPS....
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 05:50 PM
Hi Sohail,
Where would I put this script to get it to work?
Regards
Mike