sys_email which notification is used ?

poyntzj
Kilo Sage

I am looking to determine if a business rule should run when an entry is added to sys_email

I currently have 2 criteria where if either is true, we should run the rule and possibly add an attachment.

  1. users email address
  2. The notification used starts with 3P

 

I have these as part of a Script Include that is called

 

Option 1 is easy and works

Option 2 looks fairly easy in that you get the sys_id of the email itself, look at the sys_email_log table, locate the entry where the email.sys_id is your email ID and the notification.name.toLowerCase().startsWith('3p')

 

This works fine calling the   fine when run via a background script using an existing entry from sys_email.

 

I put it into the business rule (an on before) and no attachments were added, but I know the template does start with 3p so was a little bemused   (the call to check the notification template indicates it is false)

I added an extra function to the include so that I can report on the name of the template from the sys_email_log table and that came back as 'undefined' which explains why I was getting a false return on the notification template.

(on checking against an existing entry, the correct name was displayed)

 

Of course, the sys_email_log is clearly added after the entry is added to the sys_email table and is why it is not there

 

SOOOO, is there a way I can determine from the sys_email entry what notification was used in its generation ?

 

Cheers

1 ACCEPTED SOLUTION

Nothing if I look at all the fields on the current record either.


View solution in original post

9 REPLIES 9

ChrisPearson
Tera Contributor

I had to do one of these for a customer a while back and you're right about the notification not being linked to the sys_email record prior to insert.   The way I did it was look for a very specific string in the subject field on sys_email...which will be set by your notification.



//Check if we have the right email


var index = current.subject.indexOf('XYZ abc');


if (index != -1 ){


        //attach our file


}


I have a Business Rule that on insert checks the headers if it contains the sys_id of the notification i want it to trigger for.  This seems to be working for me...

poyntzj
Kilo Sage

Hi Chris


I could go that way, but the messages are pretty standard on the headings - as decreed by the management....


I guess I could put something into the body as an alternative, but again, they are management approved notifications.



Doing it via email address is not a problem as there are not too many, but it does mean that if we start to ebond via email with another company we need to amend a Script Include too.



I designed our email ebonding to work off events and notifications based on those events.     I ensured that any 3rd Party notification had its name start with 3P to make it very easy to identify for other people.


I was trying to make the integration a little easier by checking for a few specific addresses and if the notification used started with 3P.



Still, kept me quiet for a little while and I now know.


userpoth1
Tera Contributor

You can pull the notification's sys_id out of the sys_email's headers property. It's not an ideal solution, but it is a way to get what you need for a before business rule. I'm in a Madrid instance.

did you get on this?