copy attachment from RITM to approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 03:25 AM
Hello Experts
We are trying to copy attachments from RITM to sysapproval table.
I have created below BR but unfortunately not working pls correct me,
Table :sc_req_item
When : After and Insert
Filter condition :
Item is "X"
Script :
(function executeRule(current, previous /*null when async*/ ) {
attachApproval();
function attachApproval() {
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sys_id', current.sysapproval);
gr.query();
while (gr.next()) {
GlideSysAttachment.copy("sysapproval_approver", gr.sys_id, "sc_req_item", current.sys_id);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 04:19 AM
Hi @akin9 ,
You can make the following changes to your code :
(function executeRule(current, previous /*null when async*/ ) {
attachApproval();
function attachApproval() {
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
while (gr.next()) {;
GlideSysAttachment.copy("sc_req_item", current.sys_id, "sysapproval_approver", gr.sys_id);
}
}
})(current, previous);
But notice, that this business rule will only run if you update/insert a RITM record. If for example, you have a RITM and add an Attachment but doesn't make any modification on the RITM form the BR will not run.
If this is an issue, you can create a Business Rule on the sys_attachment table.
If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 04:44 AM
Hello @Clara Lemos ,
Thank you for the quick reply!
Above code is working fine , but whenever RITM is updated .
Can you help me on if attachment is attached it needs to be copied.Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 04:55 AM
This is another reason you don't want to copy attachments. You are creating more technical debt with now at least two Business Rules that don't need to exist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 04:26 AM - edited 11-15-2023 04:41 AM
First check the When to run - this Business Rule will only trigger when (after) the RITM record is created - so only if an attachment is added to the request form. You could add a log statement inside the function to be certain it is triggering. Your GlideSysAttachment parameters are backwards from your description - as written this would copy an attachment from and approval record to a requested item record
Copying attachments should be avoided wherever possible as this unnecessarily bloats the database, and is not kept up to date when the attachment(s) change. A better approach is to create a related list and add it to your Approval record so that the current attachments of the record being approved are always displayed. Create a relationship that looks like this