Dynamic email recipients based on form field values

I worked with a client last week to address a specific use case that he presented and I want to share it with the FEB world.  The form had a dropdown with multiple values and depending on which selection the user makes the form needs to send an email to a different recipient.  There are a few different ways that one can accomplish this kind of task, but here is what I suggested.


1. In the properties of the dropdown, select Events and click the onItemChange event.
2. Add some javaScript that will set the value of the email field to the appropriate email based on the selected value, something like:          
                                                                        

var ddVal = BOA.getValue();  //the selected dropdown value                                          
var emailVal = "";                                                      
if(ddVal !== "" && ddVal === "A") {                                     
  emailVal = "a@ibm.com";                                         
} else if(ddVal !== "" && ddVal === "B") {                              
  emailVal = "b@ibm.com";                                         
} else if(ddVal !== "" && ddVal === "C") {                              
  emailVal = "c@ibm.com";                                         
}                              

BO.F_Email.setValue(emailVal);   //sets the email field to the email based on user selection


3. Hide the email field using javaScript in the onLoad event of the form:

BO.F_Email.setVisible(false);

                                                                     
4. Then in your submit button, go to the advanced tab and add an email activity.  Then in the TO field, select the email field from the "Insert Item" button; this will enter a *wild card* which will be replaced at run-time.  It is important to note that you cannot type out the wild cards, you must use the insert button as it embeds some special hidden code into the field.

There are many ways to do this but this is one of the ways that I prefer.  I hope you find this short description helpful as you build and play with FEB!