
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 03:33 AM
Hi,
I have a 'attachment' type variable in my record producer which i have made mandatory. When the user uploads any attachment, i want the attachment to get saved in the record created. But instead, it is hiding it.
I can see the entry created in sys_attachment but under table name field, a prefix ZZ_YY is getting added which is making the attachment hidden.
Please find the field below -
Record in sys_attachment -
Can anyone help me get this attachment added in the record as it happens when add any attachment from here -
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2021 06:05 AM
This worked well for me
1) I created Async After Insert BR on the target table
2) Script as this
a) Remove the ZZ_YY
b) Then use the Copy Attachment
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
gr.addQuery("table_sys_id", current.sys_id);
gr.query();
if (gr.next()) {
gr.table_name = current.getTableName();
gr.update();
new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id);
}
})(current, previous);
Output:
1) The file added to the record
2) The file present on the attachment variable
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
‎03-25-2024 08:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 12:55 PM
Hi Ankur, I tried this but it's not working. Here are the steps I followed -
1. Created a cross application scope record (sn_compliance_policy_exception to sys_attachment)
2. On the policy exception table, copied your code in the BR
- when to run: Async, Insert
- script:
3. Created a new exception request on the portal, submitted it.
Result:
1. Attachment available on the sys_attachment table with the ZZ-YY prefix
2. Checked the exception record - no attachment
what am I missing here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 11:49 AM - edited ‎04-16-2024 11:50 AM
I got this to work. I removed the script where the table name is getting updated as I only wanted the attachment to show on the record. So my new script is as follows -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 07:25 PM
Hi @sayalisheth
for me table sys id is showing empty in attachment table. So gr.query is returning 0 . As the table is scoped application table im assuming table sys id empty . Please help here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 10:15 AM
im facing similar issue. In my case table sys id showing empty in sys attachment table so business rule is not working . Please help that im not sure why table sys id is empty. Im unable to copy attachment from attachment variable type to the record