Copy multiple attachments from orderguie attachment variables to RITM

Thanvik1
Tera Contributor

I have 3 attachment variables in order guide, i wrote a below business rule to map those attachments to the RITM, but it is copying only one attachments other 2 are not.

 

(function executeRule(current, previous /*null when async*/) {
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);
    }
we need map all three attachments to the RITM table. 
4 REPLIES 4

G Ponsekar
Giga Guru

Hi @Thanvik1 ,

 

Instead of if statement, use while statement to iterate multiple records

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

Sarthak Kashyap
Kilo Sage

Hi @Thanvik1 ,

 

Instead of 

new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id);
 

Can you please try with below line of code

 

var attachment = new GlideSysAttachment();
var copiedAttachments = attachment.copy('sourceTable', sourceSysID, 'targetTable',tagetSysId);
gs.info('Copied attachments: ' + copiedAttachments);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Ankur Bawiskar
Tera Patron
Tera Patron

@Thanvik1 

business rule is on which table? how the variables are shown on order guide?

share some screenshots.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanvik1_0-1762932551489.pngThanvik1_1-1762932604803.png