- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2021 11:43 PM
Hi All,
I want to copy attachment from File attachment field created on incident table to same record so it will show in manage attachment at the top of the record, can you please help.
I tried GlideSysAttachment.copy function but it didn't work.
Thanks,
Pritam
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:31 AM
Hi,
please update the script as this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
GlideSysAttachment.copy('ZZ_YY' + current.getTableName(), current.sys_id, current.getTableName(), current.sys_id);
// rename the table_name
var gr = new GlideRecord("sys_attachment");
gr.orderByDesc('sys_created_on');
gr.addQuery("table_sys_id", current.sys_id);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.table_name = current.getTableName();
gr.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2021 11:58 PM
you can use before insert/update BR as this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
GlideSysAttachment.copy('ZZ_YY' + current.getTableName(), current.sys_id, current.getTableName(), current.sys_id);
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:29 AM
Hi Ankur,
I noticed when i am using this function, it is adding ZZ_YY in destination table as well with attachment state as Pending, so it is not adding attachment in incident table but ZZ_YYincident table.
Thanks,
Pritam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:31 AM
Hi,
please update the script as this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
GlideSysAttachment.copy('ZZ_YY' + current.getTableName(), current.sys_id, current.getTableName(), current.sys_id);
// rename the table_name
var gr = new GlideRecord("sys_attachment");
gr.orderByDesc('sys_created_on');
gr.addQuery("table_sys_id", current.sys_id);
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.table_name = current.getTableName();
gr.update();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2021 12:45 AM
Thanks Ankur, Its working now.
Best Regards,
Pritam