Summary:

A number of support cases have been raised regarding the expected functionality that is in the default Email Manager scripts. The article will seek to clarify what functions are available in each script, and when they should be used.

More information:

Two default scripts are available for the Email Manager: Communications and Support.
Setting a default ruleset will cause a particular method to be called within your script file.

Communications.js

Only one ruleset is used: Create a Communication.

This script files outbound emails from CRM. This is done automatically if you’re using Sage CRM to send emails; the application will BCC the mail to the Email Manager inbox.

If you’re using another client (such as Microsoft Outlook), you will need to BCC the Email Manager mailbox.

You can also forward mails manually to the email manager mailbox.

In cases where the email is forwarded, the body of the email is parsed to find the original sender (it will usually be quoted at the beginning of the forwarded email). If you need to change this, you can do so: you can access any email header using Email.Header(“header name”).

Support.js

Track case: Mails sent to a mailbox will result in a case being created, and an email being sent out to the sender. This email is then filed as a Communication against the case. So long as the email subject contains the case reference number, any subsequent emails will be logged against the same case.

Create a case: The behaviour for this ruleset is the same as the above, but no email response is sent.

Create a Communication: The behaviour here is the same as the Create a Communication rule in the Communications.js, however only emails from addresses known to CRM will be recorded.

These scripts can be modified at will. If necessary, you can also create your own scripts and place them in the \CRM\Services\CustomPages\Scripts directory.

Rules Applied to when handling emails

When an email is received in the specified mailbox, the email database table is checked for all the people associated with the email address.

If only one person is associated with that email address, even if the email address is used as a private and business type, a communication is created for that person, which is also associated with the CRM user.

If an associated person cannot be found, or if multiple people are associated with the address, the email table is checked for an associated company and a communication is created for that company. This is also associated with the CRM user.

The following three core functions are at the core of the support.js file, and are run in the following order:

  1. BeforeMainAction
  2. MainAction
  3. AfterMainAction

BeforeMainAction and AfterMainAction are declared in the support.js file. MainAction is not declared. The MainAction function is generated from the rules defined on the Rules input form in CRM. The function should never be declared explicitly in any custom JavaScript file used with the Email Manager.

Debugging

Set the following at the beginning of your JS file:

MsgHandler.Debug = true;

You can then add logging using MsgHandler.Log(String);

Additional rulesets can be added, with conditions based on the company, user or person who was the originator of the email. This allows you (for instance) to assign a new support case to a user based on the email's sender.