Copy Attachment from ritm to task and vice versa without looping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 12:29 PM
I have to copy the attchment from ritm to task and also from task to ritm ....but it goes in the loop when do it using the business rule ....pls help
how can i break the loop in the business rule ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 12:41 PM
Hi rahul,
Please refer below link:
Thanks,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 11:32 PM
In my requirement i dont want to do it using the related list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2020 11:44 PM
Hello Rahul,
Can you share your code so we debug?
Thank You!
Abhishek Gardade
ServiceNow MVP 2020
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 12:12 AM
Yeah sure
from ritm to task
(function executeRule(current, previous /*null when async*/ ) {
var reqtask = new GlideRecord('sc_task');
reqtask.addQuery('request_item', current.table_sys_id);
reqtask.addQuery('table_name', 'sc_req_item');
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);
from task to ritm
(function executeRule(current, previous /*null when async*/ ) {
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);
}
})(current, previous);
Till here it is working fine just helpme how can i break the loop