- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 08:57 AM
Your solution to the original problem worked well when I added the business rule.
However, in my catalog item I have 2 attachment variables. Your scripted BR is only picking up the attachment from one of the attachment variables.
How can the script be changed to look for both (all) attachment variables on the current RITM record?
Your help will be creatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 09:25 AM
I modified the script after seeing another comment from you about the OOB syntax change.
New code is
(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().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);
}
})(current, previous);
After running a new test, this time the script saw 2 attachment variables BUT it only copied one file twice to the sys_attachment table.
the resulting sys_attachments showing in the sub-header - both files the same
 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2024 09:25 AM
I modified the script after seeing another comment from you about the OOB syntax change.
New code is
(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().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);
}
})(current, previous);
After running a new test, this time the script saw 2 attachment variables BUT it only copied one file twice to the sys_attachment table.
the resulting sys_attachments showing in the sub-header - both files the same
 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2025 08:44 PM - edited ‎03-18-2025 08:44 PM
Hi @kshaw
Please try the below script and confirm if it picks up all the attachments from variable.
(function executeRule(current, previous /*null when async*/) {
var atch = new GlideRecord("sys_attachment");
atch.addQuery("table_name", "ZZ_YY" + current.getTableName());
atch.addQuery("table_sys_id", current.sys_id);
atch.query();
while (atch.next()) { // Loop through all found attachments
var oldSysId = atch.sys_id; // Store the old sys_id before updating
atch.table_name = current.getTableName();
atch.update();
new global.VariableUtil().copyAttachment(oldSysId, current.getTableName(), current.sys_id);
}
})(current, previous);
Regards,
Sathish Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 08:35 AM
I am not an expert, but it may be because you are using if instead of while? so it's only picking up the first one. Just a guess.
I am trying this in my instance with one variable and the BR doesn't seem to work. Can you let me know where you wrote the BR and if it was set to Before/After/Async and on Insert or Update?
Thank You!