- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2021 10:19 AM
Recently Servicenow added a new variable type named attachment and it works great. Here is my question. When that variable is used on the catalog item , it attaches the file in the work note in the case created. That location is different from where the files is attached when using the paper clip . Is here a way to make the new variable attachment add the file to the top of the case as when you use the paper clip?
Solved! Go to Solution.
- Labels:
-
Case and Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2021 08:04 AM
I have shared working solution in this link below
Disable ZZ_YY prefix from attachment when added through record producer
Adding the same here for your reference:
1) I created Async After Insert BR on the sc_req_item table
2) Script as this
a) Remove the ZZ_YY
b) Then use the Copy Attachment functionality
(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);
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-16-2021 01:43 PM
Hi Gabriel,
I'm personally not a fan of the attachment variable type. There may be something more to this that I'm not aware of, but from what I can see I am absolutely shocked that ServiceNow has implemented it this way. First of all, you can only add one file, and it (almost) replicates existing functionality, so what is the point? And putting the attachment in the Work note instead of where it belongs? Wwwhhhyyy? So much confusion. I've used a Macro variable with this simple XML to create an Attachments button that I can order wherever within the variables, and it opens the same dialog window as the the paper clip, so same functionality, no excessive records on the attachments table, and they appear where you expect them to. This method doesn't work in Service Portal since Macro variables are not supported.
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<button class="request_catalog_button_with_icon btn cat-btn btn-primary" onclick='attach()'>Attachments</button>
<script language="javascript">
function attach() {
saveCatAttachment(gel('sysparm_item_guid').value, 'sc_cart_item');
}
</script>
<!-- </td></tr></table> -->
</j:jelly>
The thing I'm most shocked about is that when you attach your one file on the request form then submit the item, you will see in the sys_attachment table that there are now TWO records for the same file - the very thing they preach against the copy attachment utility - they're unnecessarily bloating the database unbeknownst to most. The ZZ_YYsc_cart_item record serves no purpose and should be deleted when the RITM and it's attachment are created, if they're going to do it that way.
If you prefer the look/functionality of the variable over a UI Macro button, a simple before or after Insert Business Rule on the sys_attachment table should put the attachment where it belongs and should have been in the first place, but there seems to be something in place preventing this from working, so there's more than one way to skin this cat. Create an after Insert Business Rule on the sc_req_item table, with no Filter Conditions. Your script will look like this.
(function executeRule(current, previous /*null when async*/) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_name', 'ZZ_YYsc_req_item');
attach.addQuery('table_sys_id', current.sys_id);
attach.query();
while(attach.next()){
attach.table_name = 'sc_req_item';
attach.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2022 09:26 PM
Hey Brad,
I'm on the same boat. Not a fan of Attachment variable for the reasons you mentioned.
Since Macro's aren't supported on Portal, any ideas on how to replicate the functionality of opening paper clip Add Attachment (SC Catalog Item widget) when clicking on a custom button on portal?
I tried a Macro with Widget and it didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2024 04:12 PM
hello Brad,
i have the same query related to attachment variable. The attachment is getting downloaded by admin and not by any ITIL User. Is there any possible troubleshooting i can do to find the cause. I have posted one question also.
Re: Attachment not able to download from RITM - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2021 07:15 AM
Thank you Brad
My intend here was to be able to make that attachment mandatory when some values are selected on the preview variable and when I saw this new attachment variable , I said horah but that was too soon. Do you or anyone found a way to make this paper clip mandatory only for some other variable value on the catalog? In case I have to go back to the paper clip