- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2021 07:55 AM
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.
Solved! Go to Solution.
- 2,426 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2021 08:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2021 08:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2021 08:33 AM
Thanks Brad. Not going to beat my head against the wall wondering why. I'm just glad it works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2021 02:18 PM
One additional question. Since I have to create this in the Global scope it's not part of my scoped app. I've seen articles that suggest using a Script Include instead. Have you seen that and would that be called with an onSubmit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2021 04:57 PM
You would replace the BR script with a call to the Script Include. I'm not sure if they're suggesting the BR runs in the scope and the SI is in Global? That makes more sense than the other way around, but I haven't tested this to see if it will work with multiple attachments, and I'm not sure what you gain by doing this. If you want to give it a try, the contents of your BR script will go in a SI in Global, and the BR script becomes something like this.
(function executeRule(current, previous /*null when async*/) {
new global.SIName().functionName(current);
})(current, previous)