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 11:49 PM
Hello Rahul,
in order to avoid loops, you have to use the sentence glideRecord.setWorkflow(false) to not to run business rules in your update.
Un saludo,
Pablo Espinar
Consultant at Econocom Spain
Please mark this response correct if I've answered your question. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 12:17 AM
above i posted my code in the comment how should i use this in my code ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 12:18 PM
I got the Solution to break the loop
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('table_sys_id=' + reqtask1.sys_id + '^sys_updated_onBETWEENjavascript:gs.beginningOfLastMinute()@javascript:gs.endOfCurrentMinute()');
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('table_sys_id=' + reqItem.request_item + '^sys_updated_onBETWEENjavascript:gs.beginningOfLastMinute()@javascript:gs.endOfCurrentMinute()');
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2022 06:57 AM
On which form we should add above business rule ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:35 AM