How to avoid the business rule to run every time on the Request table?

srinithi Venkat
Tera Contributor

Requirement: I need to populate the attachment on the record to the email client template.

To achieve that, I created one Business rule on the sys_email table

  • When to run >> After Insert
  • Condition added: Email.target table is Request table.

In advanced: I added the below script:

" GlideSysAttachment.copy('Request Table', current.instance, 'sys_email', current.sys_id);"

Query:

 This business rule is triggering on each and EVERY email for the Request table, that is inbound/outbound, manually/automatically triggered, etc. I checked this by adding logs in the Script. How to add appropriate when to run conditions? Kindly suggest a solution. Thanks in advance @Ankur Bawiskar 

3 REPLIES 3

DrewW
Mega Sage

Its difficult to suggest a filter that will prevent the BR from running for every email from a request when you did not give us any idea of when you wanted it to run.  Do you want it to run only for certain notifications or certain times of the day?  We need more information.

 

I need to run my BR when the record contains attachments.

srinithiVenkat_0-1689871316103.png

When I click on more options > Email then only I want this BR to be triggered.

I believe you will need to use a script to check to see if there are no records in the sys_email_log that indicate that the email is because of a Notification.  So if you query sys_email_log where email column = the current record and you get nothing then its probably because it was sent via the email client, but that may not be 100% accurate but should be close enough.