- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 06:32 AM - edited 07-07-2025 06:33 AM
I have created workflow and created inbound email to get attachment from the user and the attachment should be copied to demand. I created BR for this part is working fine but after checking attachment in demand it should trigger approval but it seems to be workflow is stuck.
BR:sys_email
After insert, update
condition: subject contains INC
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 06:51 AM
wait for condition only works if workflow is waiting on current record.
your workflow wait script is checking sys_attachment but workflow is on other table (Demand)
you need to broadcast update to that workflow so that it check the wait for condition script again
use this in your business rule
(function executeRule(current, previous /*null when async*/ ) {
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);
var record = new GlideRecord('dmn_demand');
record.get(current.instance.sys_id);
new Workflow().broadcastEventToCurrentsContexts(record, 'update', null);
}
})(current, previous);
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-07-2025 06:45 AM
You could have done this with an inbound flow. The attachment could be copied to the record and you could just proceed from there, including the approval step. No need for any scripts.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 06:51 AM
wait for condition only works if workflow is waiting on current record.
your workflow wait script is checking sys_attachment but workflow is on other table (Demand)
you need to broadcast update to that workflow so that it check the wait for condition script again
use this in your business rule
(function executeRule(current, previous /*null when async*/ ) {
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);
var record = new GlideRecord('dmn_demand');
record.get(current.instance.sys_id);
new Workflow().broadcastEventToCurrentsContexts(record, 'update', null);
}
})(current, previous);
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-07-2025 07:37 AM
Hi @Ankur Bawiskar , I updated BR after attaching file it is triggering random approval from the workflow. It should be sequential and for the demand it it attaching multiple attachment. like 1from the system, 2from the user who sent it (all are same attachment), Do I need to update workflow(update/remove wait for condition)? And this time when system spending for approval it should send mail to approves for approve/reject it with the attachment present on current record.