- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 04:15 AM
Hi All,
I have written a Business rule to copy attachment from sys_attachment to hr_case table when someone sends and attachment via the email client template on a hr record.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var sys_id=current.sys_id;
if(current.target_table=="hr_case"){
var gr= new GlideRecord('sys_attachment');
gr.addQuery("table_sys_id",sys_id);
gr.query();
if(gr.next()){
GlideSysAttachment.copy('sys_attachment', gr.sys_id, current.target_table, current.instance);
}
}
gs.info("completed");
})(current, previous);
But it is not working. I cannot see any attachment on HR Case table.
Also in the logs I see the following warning : "syslog_transaction not found for AjaxClientTiming: sysId: , table: , view: Default view, form: email_client_template"
Any help would be appreciated
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 04:20 AM
Hi Sidarth,
The key to making this work is to find out what the real record is that the attachment is linked to. The attachment is IN sys_attachment, but it is not attached to a sys_attachment record.
If you look in sys_attachment for that record, you will see the table name (see example image below.)
THAT is going to be your source table and sys_id to use in the first arguments. The target table will be the current record's information (see 3rd and 4th args below.)
GlideSysAttachment.copy(sourceTable, sourceSysId, current.getTableName(), current.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 04:19 AM
HI ,
Try this :
v
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var sys_id=current.sys_id;
if(current.target_table=="hr_case"){
var gr= new GlideRecord('sys_attachment');
gr.addQuery("table_sys_id",sys_id);
gr.query();
if(gr.next()){
GlideSysAttachment.copy('sys_attachment', gr.sys_id, current.target_table, current.sys_id); //current.sys_id
}
}
gs.info("completed");
})(current, previous);
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 04:25 AM
will this work? Current.sys_id will give me the sys id of the email table record. But I want the sys_id of the HR Case record

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 04:27 AM
First, find out where the source record really is. You believe it has a record in sys_attachment... what table is that attachment attached to?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2016 04:20 AM
Hi Sidarth,
The key to making this work is to find out what the real record is that the attachment is linked to. The attachment is IN sys_attachment, but it is not attached to a sys_attachment record.
If you look in sys_attachment for that record, you will see the table name (see example image below.)
THAT is going to be your source table and sys_id to use in the first arguments. The target table will be the current record's information (see 3rd and 4th args below.)
GlideSysAttachment.copy(sourceTable, sourceSysId, current.getTableName(), current.sys_id);