Mail Script - how to get sys_id of current email

Tom Sienkiewicz
Mega Sage

Hi, I need to be able to get the sys_id of the email being sent out inisde the mail script. 

Anyone have suggestions on how this could be done? This has to work for both email notifications and e-mail sent using Email Client.

I thought the "email" or "email_action" object would help but it seems none of those objects allow to get the sys_id of the current email.

Thanks in advance for any pointers.

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

what's the business use-case/requirement for this; if you explain that would be easier to provide some update

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Tom Sienkiewicz
Mega Sage

OK guys let me clarify a bit what I want to achieve 🙂 I was able to get the e-mail sys_id for email client, but this does not work for notifications apparently.

I want to add a link into the email, which after clicking, will take the user to a page that does something. In order to do that something, the page has to know which email the user clicked from.

So my idea was to grab the sys_email table sys_id and put that into the URL as a parameter. 

I am now thinking this may not be possible for emails coming from email notifications,...

 

So...I was thinking in inbound actions, you can use: sys_email.sys_id...even though it's not "obvious' that you can do that...can you try that in your mail script to see if that'll also work for the outbound?

I'm not sure, but I'm thinking the email hasn't been officially sent yet or inserted in to the sys_email table so that may be why we're having trouble grabbing the sys_id.

The other thing would be trying to figure it out through a business rule and seeing if you can add a link to your email (if 'x' conditions apply) using script in that BR.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Exactly! I think, as opposed to Email Client, for Notifications the email record does not yet exist when mail scripts are running.

Unfortunately "sys_email.sys_id" did not work.

So I'm in a bit of a pickle here. I may have to create my own "watermarking" system where I will be adding hidden "custom ID" to the body of every email and also adding it to the URL, then looking through emails in the UI Page script.

But that is not very elegant now is it?

Ah, and regarding the BR, I suppose this would be on the sys_email table? The thing is, it is a scoped application, so that might be hard to certify for the Store. I don't think we are allowed to add BRs for the email table but will double check.