Awaken Scripting User Guide

Please email helpdesk@awaken.io for omissions or errors.
×
Menu

Sending Emails with JavaScript

 
JavaScript can be used to send an email at any time in a Workflow, and can be a preferable method of sending automatic emails built from the content of multiple Fields.
 

How To

Inside any JavaScript-manipulating Field (Calculate, JavaScript, JavaScript - Button), use the function specified below.
 
Simple Syntax
The simple syntax requires a list of parameters:
Script.Email.Send(connectorType, connectorName, subject, recipients, from, body, defer, callback);
 
Name
Required / Optional
Explanation
connectorType
Required
This is the type of connector to be used, and must be set to "connector-email-outbound" for this function.
connectorName
Required
This is the Connector Name of the Email (Outgoing) connector that you wish to use to send the email.
subject
Required
This is the subject line of the generated email.
recipients
Required
These are any recipients of the generated email, provided either as an array of strings, or as a comma- or semicolon-separated string.
from
Optional
This is the address the email will appear to be sent from. If not provided, then the default specified in the connector itself will be used.
body
Required
This is the body of the email.
defer
Optional
This is the time to defer sending of the email to, specified either as a JavaScript date object or a string in the format "YYYY-MM-DD hh:mm:ss". If not provided, then the email will be sent immediately.
callback
Optional
This allows the provision of a "callback" function which will be executed once the email scheduling attempt has returned, allowing you to react to either successful or failing email scheduling.
 
 
Example:
 
Script.Email.Send(
    "connector-email-outbound",
    "Outbound Mail Example Connector",
    [Email Subject],
    "a.bc@example.com,d.ef@example.com",
    "agent@example.com",
    "Hi, this is a reminder for your appointment tomorrow...",
    "2019-07-10 12:00",
    function(response) { if(response.Error != "") { Script.Toast.Error("Email Failure", response.Error); } }
);
 
 
Alternate Syntax
Since many of the arguments for the above syntax are optional, there is an alternate syntax where a JavaScript object is passed instead. This means that only the desired optional parameters need to be passed:
 
Script.Email.Send({
    connectorType: "connector-email-outbound",
    connectorName: "Outbound Mail Example Connector",
    subject: [Email Subject],
    recipients: ["a.bc@example.com", "d.ef@example.com"],
    body: "Hi, to confirm the details of your recent enquiry...",
    callback: function(response) { if(response.Error != "") { Script.Toast.Error("Email Failure", response.Error); } }
});
 
 
Any optional parameters that are omitted will use their default value, as stated in the above table. As this is a JavaScript object, the order in which the parameters are listed in this alternate syntax doesn't matter, as long as the key:value pairs are preserved.
 
 

Notes

As multiple duplicate emails can be queued, it is advised that caution is used if this function is invoked in a Calculate Field, due to the way that Calculate Fields will run every time an action is taken or Field's value is altered.
 
It is also possible to make use of the Script.Message.Send() function to send both SMS and emails.