How to copy attachment of REQUEST into SC Task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2024 09:36 PM
Hii all,
I have a requirement of attachment while submit a catalog it generate request give an attachment to it and copy it into sc_task table
how it can be achieve?
Regards,
Suyash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2024 10:07 PM
Hello @Suyash Joshi
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 ā Correct if this solves your issue and also mark š Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2024 11:49 PM
Hi @Harsh_Deep
First I want to tell you something about the community you can copy someone answer and re-paste but we user also check the articles you paste above.
Try to paste article links instead of solution.
And if you have knowledge about my requirement help me with my script:
Business Rule After Insert -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2024 12:40 AM
Hello @Suyash Joshi
Create After BR on sc_req_item table
Use this script-
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideSysAttachment();
var success = attach.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);
if (success) {
gs.addInfoMessage("Attachments copied ");
} else {
gs.addErrorMessage("Failed to copy attachments from Request to Task");
}
gs.info("Business Rule executed for sc_task: " + current.sys_id);
gs.info("Attachment copy success: " + success);
})(current, previous);
Mark ā Correct if this solves your issue and also mark š Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2024 12:49 AM
Your script is good I guess from AI Chat GPT but the attachment is not visible in sc_task form but you can try my script:-
After Insert Business Rule-