- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2020 08:42 PM
Hi,
We have a requirement that the attachments added on to the request should get automatically added on to the tasks related to that request.
1)While creating the request users will add attachments to the request and after creating the request also users will add and the tasks will generate later based on the workflow trigger conditions. whenever, the tasks generated for that request all the attachments present on the request should get added to the task.
2)In the flow there are so many tasks will generate one after one, and the attachments should added to all the tasks even the closed tasks in the flow.
Can any one please help me on this.
Solved! Go to Solution.
- Labels:
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2020 03:50 AM
Please try below code, tested it works as expected.
script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var copyFrom = new GlideRecord(current.table_name);
copyFrom.get(current.table_sys_id);
var id = current.table_sys_id;
var copyTo = new GlideRecord('sc_task');
copyTo.addQuery('request_item',id);
copyTo.query();
if(copyTo.next()){
var task = copyTo.getUniqueValue();
}
copyAttachments(copyTo.getTableName(), task);
deleteDuplicateAttachments(task);
/************************** functions *****************************/
function copyAttachments(table, sys_id){
var attachmentUtil = new GlideSysAttachment();
attachmentUtil.copy(current.table_name, current.table_sys_id, table, sys_id);
}
function deleteDuplicateAttachments(sys_id){
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', sys_id);
gr.orderBy('hash');
gr.orderBy('file_name');
gr.orderByDesc('sys_created_on');
gr.query();
var lastHash = 'not_a_match';
var lastFileName = 'not_a_match';
while(gr.next()){
var isDuplicate = false;
if ((lastHash == gr.hash) && (lastFileName == gr.file_name)){
isDuplicate = true;
}
if(isDuplicate)
gr.deleteRecord();
lastHash = gr.hash.getValue();
lastFileName = gr.file_name.getValue();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2020 09:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2020 09:07 PM
Hi,
You could use GlideSysAttachment.copy('sourcetable','sys_id','destinationtable','sys_id'); in TASK activity if you are creating task via workflow
Copy attachments from record to record
GlideSysAttachment.copy('sc_req_item',current.sys_id,'sc_task',task.sys_id);
OR use flow designer instead of Business Rule
Regards,
JAS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2020 10:46 PM
Hey Sriniwas,
refer below links might help you,
kindly mark Correct and Helpful if applicable.
Regards,
Indrajit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2020 07:45 AM
Hi, the issue here is whenever the attachment is added to the request then automatically the attachments should appear in the tasks.
in my case, it is working only if some update happened on the task then only the new attachments populating on the task.
Thanks,
Sriniwas