If task has attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 12:33 AM
I have a True/false field "u_attachment" on sn_customerservice_task table to show if the task contains attachments. Below Business rule was created to set the checkbox, on insert it is working correctly when attaching attachments to the case task, however when i am removing the attachments it is not setting the checkbox to false, can someone help what i am missing?
BR written on sys_attachment table:
Condition: current.table_name == "sn_customerservice_task"
(function executeRule(current, previous /*null when async*/) {
checkAttachment();
function checkAttachment(){
// if inserting then the task has an attachment
if (current.operation() == 'insert') {
hasAttachment('true');
}
// if deleting attachment check for other attachments
if (current.operation() == 'delete') {
var attachments = new GlideRecord('sys_attachment');
attachments.addQuery('table_sys_id',current.table_sys_id);
attachments.query();
// if no other attachments task does not have attachment
if (!attachments.next()) {
hasAttachment('false');
}
}
}
function hasAttachment(answer) {
var task = new GlideRecord('sn_customerservice_task');
task.addQuery('sys_id',current.table_sys_id);
task.query();
if(task.next()) {
task.u_attachment = answer;
task.setWorkflow(false);
task.autoSysFields(false);
task.update();
}
}
})(current, previous);
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 01:56 AM
current.operation() == 'delete'
This is delete record
Delete attachment
It should be current.operation() == 'update'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 11:10 AM
Hi Panda,
This doesn't work either!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2022 07:18 PM
Sorry, I didn't see it clearly.
BR written on sys_attachment table,I don't see here
1.Do you select Insert and delete in BR condition
2.use after Business rule
var attachments = new GlideRecord('sys_attachment');
attachments.addQuery('table_sys_id',current.table_sys_id);
attachments.query();
// if no other attachments task does not have attachment
if (!attachments.next()) {
hasAttachment('false');
}
When the before business rule is used, the DB data has not been deleted when the query is executed, so next = true