Tip #1198: Add email address to recipients in javascript

The advantage of having access to friendly brainpower is that the problems are getting resolved much quicker. The disadvantage is that it breeds inattentive coding. Daryl “Always Raising” LaBar almost threw in a towel but recovered and redeemed himself with the snippet how to add an arbitrary email address to the list of the email recipients on the email form.

function appendToEmail(executionContext)
{
var formContext = executionContext.getFormContext();
// prior to v9: Xrm.Page

var att = formContext.getAttribute('to'); // or 'cc'
var emails = att.getValue() || [];
emails.push({name: 'george@foobar.com', type: '9206'});
att.setValue(emails);
}

Potential gotchas:

  • the property is type not entityType as one would expect
  • sending emails to arbitrary recipients must be enabled in System settings

image

(Facebook and Twitter Cover photo by Mathyas Kurmann on Unsplash)

Leave a Reply

Your email address will not be published. Required fields are marked *