- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 11:01 AM
Hi
I want to copy attachment from RITM to SC Task. There are two scenario
- Attachment attached while submitting the request
- Attachment attached by end user from portal (Updates to RITM).
I have below AFTER BR on insert and it is working fine but not in all scenario:
- Below BR is not working if attachment is attached while submitting the request.
- If User attached 2nd attachment, it copy all attachment to SC Task (On updates). As of now, I am cleaning existing attachment and copy all once again to SC Task but it changes timestamp of the Attachments
Any suggestion, specially on point 1.
-----------------------------------------------------------------------------------------------------------------------------------------------
(function executeRule(current, previous /*null when async*/) {
updateTasks();
function updateTasks()
{
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item' , current.table_sys_id);
gr.query();
//gs.log("row count: "+ gr.getRowCount(),"test");
if(gr.next())
{
var at = new GlideRecord('sys_attachment');
at.addQuery('table_sys_id', gr.sys_id);
at.deleteMultiple();
GlideSysAttachment.copy('sc_req_item', gr.request_item, 'sc_task', gr.sys_id);
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
-
Workflow
- 21,333 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 11:52 PM
Hi Vishrut
Thanks for response.
I did the same way, wrote BR on SC Task on Insert to copy attachment from RITM To SC Task.
We had 3 scenario:
- Scenario 1: Copy Attachment from RITM to SC Task when Request is submitted from Portal.
- After BR on Insert on sc_task
(function executeRule(current, previous /*null when async*/) {
GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);
gs.info(current.number);
})(current, previous);
- Scenario 2: Copy attachment, when requester update from Portal.
- After BR on Insert on sys_attachment table. Below code does not work on Submit.
(function executeRule(current, previous /*null when async*/) {
updateTasks();
function updateTasks() {
// Add your code here
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item' , current.table_sys_id);
gr.addQuery('x_fru_dynamic_wf_workflow_step', 'b6fb44e9db9ed7001588753a8c9619a2');
gr.query();
// gs.log(current.table_sys_id);
while(gr.next())
{
// gs.log(gr.number);
var at = new GlideRecord('sys_attachment');
at.addQuery('table_sys_id', gr.sys_id);
at.query();
if(at.next())
{
at.deleteMultiple();
}
GlideSysAttachment.copy('sc_req_item', gr.request_item, 'sc_task', gr.sys_id);
}
}
})(current, previous);
- Scenario 3: When eBonded system upload attachment to SC_Task, it should be visible to end user.
- After BR on Insert on - sys_attachment table.
- Here need to be careful. Scenario 2 & scenario 3 may go into infinite loop. So I we used integration user in condition to make sure below BR run only if user is integration user.
(function executeRule(current, previous /*null when async*/) {
updateTasks();
function updateTasks() {
//var sctaskSysId = current.table_sys_id;
var gr = new GlideRecord('sc_task');
gr.addQuery('sys_id', current.table_sys_id);
gr.addQuery('x_fru_dynamic_wf_workflow_step', 'b6fb44e9db9ed7001588753a8c9619a2');
gr.query();
// gs.log(current.table_sys_id);
while(gr.next())
{
//var itemSysId = gr.request_item;
var at = new GlideRecord('sys_attachment');
at.addQuery('table_sys_id', gr.request_item);
at.query();
if(at.next())
{
at.deleteMultiple();
}
//GlideSysAttachment.copy('sc_req_item', , 'sc_task', gr.sys_id);
GlideSysAttachment.copy('sc_task', gr.sys_id, 'sc_req_item', gr.request_item);
}
}
})(current, previous);
Still, I am not happy with GlideSysAttachment.copy method, it copy all attachment from source table to destination. Trying to use attachment API if it is useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 11:05 AM
I would strongly suggest you not to copy the attachments because
1. Bloats database with copied attachments
2. If the attachment is updated on either side, it doesn't reflect on the other
The best way to accomplish this is to query/show the attachments for the parent sc_req_item instead. This way the task is showing the same attachments. If your fulfillers are using the standard browser platform UI, you can create a Defined Related List to show the related attachments:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 11:12 AM
Hi Michael
Thanks for reply.
We want to copy attachment only for specific catalog item and one task. I have removed specific condition in code but its limited to one task only. The reason, we need it because these attachments are sent to enbonded system via integration. Integration is specific to task, we had to copy attachment from RITM TO SC Task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 01:18 PM
Even for an ebond you could navigate up to the parent to get the attachments versus copying. Another option is to move them versus copy - you would just update the sys_attachment record with the table and sysid of the record.
Otherwise to solve the issue you will need to loop through the sc_req_item attachment and collect metadata about them like filename, size, etc and then loop through the attachments on the sc_task and compare. If the attachment exists then don't copy, if not, copy.
The challenge you will face is what if the attachment was edited on one side, how will you know to update or if its a new and separate file of the same name. This is tricky which is why keeping them in one place vs copy simplifies this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2018 01:44 PM
Hi Michael
Thanks for your reply.
Yes, that was the natural option to get attachment from parent ticket (RITM) but ebond system do not want it to query parent. They have some business reason for this. So, we left with copying attachment to SC Task.
I am not much worried about duplicate attachments but main issue we are facing is to copy attachment when request is submitted. Attachments are getting carried to SCTask only when user attach document after request submission.
We want to move those attachment too which are attached while submitting the request.
Anything wrong with above BR? Any suggestion.