attachment from SC_task to REQ

SAM321
Tera Contributor

hi all actually i have task , when i upload any attachment in SC task form ,it should also been seen in REQUEST form related to that sc task. i tried below script but its not working .. can anyone tell whats wrong with below script , because am new to this scripting world

3 ACCEPTED SOLUTIONS

jaheerhattiwale
Mega Sage
Mega Sage

@SAM321 Tried and Tested solution.

Please add when to run condition as below image

jaheerhattiwale_0-1671016182835.png

 

Add the below script:

var taskRec = new GlideRecord(current.table_name.toString());
taskRec.addQuery("sys_id", current.table_sys_id.toString());
taskRec.query();

if(taskRec.next()){
    GlideSysAttachment.copy(current.table_name.toString(), current.table_sys_id.toString(), "sc_request", taskRec.request.toString());
}
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

@SAM321 Then keep the filter conditions same and change the script as below

 

var taskRec = new GlideRecord(current.table_name.toString());
taskRec.addQuery("sys_id", current.table_sys_id.toString());
taskRec.query();

 

if(taskRec.next()){
    GlideSysAttachment.copy(current.table_name.toString(), current.table_sys_id.toString(), "sc_req_item", taskRec.parent.toString());
}
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

@SAM321 Create scheduled job

 

Go to "System Definition > Scheduled jobs" module

Click on new button

Click on "Automatically run a script of your choosing"

jaheerhattiwale_0-1671622060034.png

 

 

add below code and save

var scTask = new GlideRecord("sc_task");
scTask.addQuery("active=false");
scTask.query();

while(scTask.next()){
    GlideSysAttachment.copy("sc_task", scTask.sys_id.toString(), "sc_request", scTask.request.toString()); //This line for moving attachments to request
GlideSysAttachment.copy("sc_task", scTask.sys_id.toString(), "sc_req_item", scTask.parent.toString()); //This line for moving attachments to requested item
}
 
click on execute button
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

27 REPLIES 27

@SAM321 Create one more business rule and just change the when to run filter condition as "Table Name is sc_req_item"

Keep the script as is.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

SAM321
Tera Contributor

@jaheerhattiwale  soryy misunderstood..... i mean what if the target table is req item (instead of request)

@SAM321 Then keep the filter conditions same and change the script as below

 

var taskRec = new GlideRecord(current.table_name.toString());
taskRec.addQuery("sys_id", current.table_sys_id.toString());
taskRec.query();

 

if(taskRec.next()){
    GlideSysAttachment.copy(current.table_name.toString(), current.table_sys_id.toString(), "sc_req_item", taskRec.parent.toString());
}
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023