Copy of attachment from variable to record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2025 07:21 AM
Hi,
I have a variable type attachment on my catalog form. Post submission of request I want to attach that attachment to the requested item so that it shows on the top of the ritm, user doesn't need to scroll down and see for variable attachment
This is what I have tried and it is not working as expected it does copy but every time it copied to ZZ_YYsc_req_item instead sc_req_item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago - last edited a week ago
Below tested with one attachment in variable, and copies fine to the RITM:
BR, async, 'insert' ticked, 'advanced' ticked, [you can add additional filter such as only for specific 'Item']
(function executeRule(current, previous) {
var attachUtil = new GlideSysAttachment();
// Query staging attachments for this RITM's variables
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
gr.addQuery("table_sys_id", current.sys_id);
gr.query();
while (gr.next()) {
var content = attachUtil.getContent(gr);
// Write a clean copy to the RITM itself
attachUtil.write(
current,
gr.file_name.toString(),
gr.content_type.toString(),
content
);
}
})(current, previous);
