- 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
‎08-02-2024 08:12 AM
i have two attachment buttons on my form but this code will only work for one of them while the other attachment shows still as ZZ_YY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2024 10:08 AM
It sounds like you have two records that meet the GlideRecord criteria, so try changing the
if (gr.next()) {
to
while (gr.next()) {
or else look at the attachment table to see how the record that isn't getting changed differs, then add that as a second GlideRecord query. Also see the update that the copy function in the referenced Script Include has been renamed to copyAttachment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2024 10:10 AM
i tried that and it causing the attachment to double meaning if i have 2 attachemtns from the two buttons it will be 4 attachment. duplicates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2024 10:14 AM
but i think i found the solution for it
here is my updated code
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var attachmentIDs = [];
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
gr.addQuery("table_sys_id", current.sys_id);
gr.query();
// Collect the attachment sys_ids
while (gr.next()) {
attachmentIDs.push(gr.sys_id.toString());
}
// Copy attachments using the collected sys_ids
for (var i = 0; i < attachmentIDs.length; i++) {
var attachment = new GlideRecord("sys_attachment");
if (attachment.get(attachmentIDs[i])) {
new global.VariableUtil().copyAttachment(attachment.sys_id, current.getTableName(), current.sys_id);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2021 11:19 AM