Copy attachments from Attachment Variable

sgmartin
Kilo Guru

Have a scoped app with Record Producers that have a number of variables using the new Attachment variable that comes with Paris.  My issue is that when the Record Producer is submitted, I need all the attachments from it copied over to the base table in the app.  I found this on the Community (sorry, can't find the article again to show who wrote it), but it's an Async Business Rule that will copy over the attachments:

(function executeRule(current, previous /*null when async*/ ) {

	var tableName = current.getTableName();
	var sysID = current.sys_id;
	
    var pcsAttachment = new GlideRecord("sys_attachment");
    pcsAttachment.addQuery("table_name", "ZZ_YY" + tableName);
    pcsAttachment.addQuery("table_sys_id", sysID);
    pcsAttachment.query();
    gs.info('Count: {0}', pcsAttachment.getRowCount());
    while (pcsAttachment.next()) {
        pcsAttachment.table_name = tableName;
        pcsAttachment.update();
        new global.VariableUtil().copy(pcsAttachment.sys_id, tableName, sysID);
    }

})(current, previous);

In the App log, it says on one example that there are 6 records found, but only 1 of the attachments is copied.  

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

I've noticed when working with async BRs like this that the script doesn't run with expected results unless the BR was created in the Global Application - even if it's running on a Table that's in a scoped app.

View solution in original post

5 REPLIES 5

Same unexpected results that I got when running the Business Rule in the scoped app.  It would only copy the first attachment.  This just makes it a bit clumsy when I go to move my scoped app from one instance to another.  I have to make sure these Global Business Rules that I need are also brought over.

Thx for your responses Brad.