Business Rule to add attachments from task to email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 01:18 AM
Hi All!
I have a Business Rule which copies attachments from tasks to email attachments when conditions are met.
Currently it checks if short description is 'Design solution' then it copies attchments.
I need to check also if tasks are assigned to the same group.
And if, for example, two tasks from three are assigned to the same group then it take attachments only from task which is newer.
How should I build a condition then?
var grtsk = new GlideRecord("task");
grtsk.addQuery("parent", nssr.getUniqueValue());
grtsk.addQuery("short_description", "Design solution").addOrCondition('short_description', "Angebot erstellen");
grtsk.query();
if (grtsk.next()) {
var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('task', grtsk.getUniqueValue(), 'sys_email', current.sys_id);
gs.info('Copied attachments: ' + copiedAttachments);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 01:59 AM
Try if this works:
var grTask = new GlideRecord('task');
grTask.addQuery('parent', current.getUniqueValue());
grTask.addQuery('short_description', "Design solution").addOrCondition('short_description', "Angebot erstellen");
grTask.addQuery('assignment_group', current.assignment_group); // assignmentgroup the same
grTask.orderByDesc('sys_created_on'); // order list with newest on top
grTask.setLimit(1); // return only first record (newest)
grTask.query();
if (grTask.next()) {
var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('task', grTask.getUniqueValue(), 'sys_email', current.sys_id);
gs.info('Copied attachments: ' + copiedAttachments);
}
It doesn't validate for the task having attachments or not, but since you aren't saying anything about that, I assume all tasks will have attachments.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark