- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:26 PM
I have created after insert business rule on sys_email table(condition: subject contains dmn). Basically when when end user reply to system mail with attachment that attachment should be copied to the demand record. Currently as per below script we are able to copy attachment from sys_attachment to demand but multiple attachment getting attached. I mean the same attachment 3 times. I want it to copy single attachment to demand. if end user send multiple email with attachment it should attach latest attachment to the demand.
(function executeRule(current, previous) {
var attGR = new GlideRecord('sys_attachment');
attGR.addEncodedQuery('table_sys_id=' + current.getUniqueValue());
attGR.query();
if (attGR.next()) {
var gsa = new GlideSysAttachment();
gsa.copy('sys_email', attGR.table_sys_id, 'dmn_demand', current.instance.sys_id);
// Trigger the workflow via event
gs.eventQueue('dmn_demand.attachment.added', current, current.sys_id, gs.getUserID());
}
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:34 PM
Hey,
I want to start with: This should be an inbound action instead of a business rule! The sys_email table is one of high traffic and should be kept free of any business rules. Especially because we have inbound email actions for these exact use cases.
Alternatively you could also use a flow to archive the same thing: Move Email Attachments to Record action
Outside of that i would assume you BR might have an incorrect trigger and thus triggers more than once (again, solve this by using an inbound action instead).
Hope this helps.
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 11:34 PM - edited ‎07-08-2025 11:51 PM
on the incoming email how many files are there?
You can simply use this line in the inbound email action and no need of any business rule
var gsa = new GlideSysAttachment();
gsa.copy('sys_email', sys_email.sys_id, 'dmn_demand', current.instance.sys_id);
gs.eventQueue('dmn_demand.attachment.added', current, current.sys_id, gs.getUserID());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 12:28 AM
I tried this but attachment is not getting attached to the demand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2025 02:47 AM
are you sure that inbound email action is triggered?
it should work fine and it has worked in past with same lines for many of us.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2025 02:03 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader