- 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
- 22,162 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-21-2022 04:25 AM
Hi Kiran Patil,
Can you please tell me what is x_fru_dynamic_wf_workflow_step that you have used in your code for query. Mine is working from your code but I m not getting this query??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-22-2023 05:57 AM
gr.addQuery('x_fru_dynamic_wf_workflow_step', 'b6fb44e9db9ed7001588753a8c9619a2');
Can I get information about this line that from which table it is taken I'm new to servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2021 04:00 AM
Hi
for me when item submitted from portal, attachment not showing. but when im submitting from native view there it showing attachemnt in sc task what might be the reason, i tried log also when i submitted from portal BR not triggering ie log msg not displaying,
help in this please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2019 06:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2020 02:10 PM
Hi Maria,
Looks interesting, could you give a better example on how it relates to creating a catalog task?
