Sync Attachment between sc_request to sc_task and visa versa
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2025 07:44 AM
I have a requirement to sync attachment between sc_request and sc_task
I tried the below script using business rule while it is working for sc_task to sc_request but not for sc_request to sc_task. Seeking your assistance.
Table: sys_attachment
when to run: After insert
(function executeRule(current, previous) {
// Validate necessary fields
if (!current.table_name || !current.table_sys_id) {
gs.error("Missing table_name or table_sys_id.");
return;
}
// Retrieve the task record
var taskRec = new GlideRecord(current.table_name);
taskRec.addQuery("sys_id", current.table_sys_id);
taskRec.query();
if (taskRec.next()) {
if (taskRec.request) {
// Copy attachment from sc_task to sc_request
GlideSysAttachment.copy(current.table_name, current.table_sys_id, "sc_request", taskRec.request.toString());
gs.info("Attachment copied from " + current.table_name + " to sc_request.");
} else {
gs.error("Request field is empty in sc_task.");
}
} else {
gs.error("No matching record found for sys_id: " + current.table_sys_id);
}
// Retrieve the request record correctly
var requestRec = new GlideRecord("sc_request"); // Correcting the table reference
requestRec.addQuery("sys_id", taskRec.request); // Query using the request ID
requestRec.query();
if (requestRec.next()) {
// Copy attachment from sc_request back to sc_task
GlideSysAttachment.copy("sc_request", taskRec.request.toString(), "sc_task", requestRec.sys_id.toString());
gs.info("Attachment copied from sc_request to sc_task.");
} else {
gs.error("No matching sc_request found for request ID: " + taskRec.request);
}
})(current, previous);
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2025 08:08 AM
Hello @JP6
Maybe this could help: Sync attachment between RITM(sc_req_item) and CatalogTask(sc_task)
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar