How do I dynamically set the TO: address in an email trigger

Posted by Rollbase User on 11-Jan-2013 15:35

I've been working on this, but would appreciate advice/examples to help me along. Scenario: Upon creation of a "consulting engagement" object, the app needs to notify people via email. The customer would like to route some notifications to a group of potential consultants based on the "engagement type" field. First thing I tried was referring in the TO: field to the related "Lead Consultant" object's userid field + "@domain.com" -- i.e. "{!R151996.userid}@domain.com" I validated and the token seems valid, but no email is sent. If I replace TO: with "{!#UPDATED_BY.email}" then I receive email as expected. Second idea is to create an email field using a formula (or expression?) field that's not shown anywhere and is just used for the email sending. That would let me create logic to determine who to send to if there is no Lead Consultant.... but seems a bit messy. Thoughts? Suggestions?

All Replies

Posted by Admin on 11-Jan-2013 15:39

Quick clarification -- the first thing I tried was because it seemed simpler and I intended to build upon it...



An engagement when first created does *not* have a related Lead Consultant, so I'll need the second idea to incorporate some logic to pick the right group of people to notify.



I created an email trigger that is called from the workflow "Assign" step. In that step, the page requires the Lead Consultant be selected -- so I know it exists.



Hope that helps clarify.



Posted by Admin on 11-Jan-2013 16:22

Update 2013-Jan-11 15:17 -- I added an email field of type "Email" to the Consultant object and that shows up in the selector drop-down in the trigger and works!



I also found the "Debugging Complex Triggers" section in the RiA book and enabled Debug -- extremely helpful!



Debug: "Sending email message: TO:@domain.com"



I'm still puzzled why {!R151996.email} works great but according to the debug the token for the userid field {!R151996.userid} is empty (I confirmed by testing the formula and picking the same consultant record that the field does return the userid.)



Posted by Admin on 11-Jan-2013 16:28

Even with this small workaround, my problem is not resolved... I now need to figure out the more complex case of dynamically creating a list of email addresses to notify when the engagement is created.



My thought about creating a new hidden field that is populated by an object script seems doable for *one* email, but problematic for multiple emails.



Ideas?

Posted by Admin on 11-Jan-2013 18:00

Please try this:



1. Create Formula field with integration name "my_email"

2. Use {!my_email} token ad "TO" parameter in "Send Email" trigger.

Posted by Admin on 12-Jan-2013 08:39

Thanks Pavel, I'll give that a try.

Any ideas why the text "userid" field isn't showing? (I know it's difficult to imagine my setup just from these descriptions, so next week I will setup a quick example to see if I can reproduce on a hosted rollbase.com account.)

Posted by Admin on 12-Jan-2013 14:29

Email addresses use special parser which works differently than regular template parser.

This thread is closed