Advanced E-mail Management: Configuring the use of a Template

2 minute read time.

In this article, I want to discuss how the Sage CRM Advanced E-mail Manager can be configured to use different functions within script templates to allow the processing of emails according to business requirements.

In an earlier article "Advanced E-mail Management: Creating a Template" I discussed how templates can be created that process inbound emails according to rules defined in script template files. These templates contain JavaScript functions that are associated with the email accounts monitored by the E-mail Manager service.

In that article, we saw that template script files have a common structure.

  • Comments
  • Initialise Variables
  • General Event Functions
    • BeforeMainAction
    • AfterMainAction
  • Main Functions
  • Utility Functions

The Main Functions area would be where you define the key behaviour "the main action" invoked by the template. It is possible for a template to contain several main functions or main actions that are associated with inbound emails and are invoked according to different defined conditions.

This is what I want to look at now.

In the screen above you will see that the Default Ruleset Action can be defined.

The option here maps to the functions defined in the template.

To allow a new function to be called from within the template then you will need to add a Translation.

For example if your template script used a function called 'SalesEnquiry()' then you would need to add the following data into the custom captions screens.

  • Caption Family: jsfunctions
  • Caption Code: SalesEnquiry();
  • US Translation: Sales Enquiry

Note. The reference to the function includes the semi-colon ;

You can then add other translations as required.

The new function would then be available as in the administration screens.

Where you only have a single function referenced in the configuration screen for the managed e-mail account this will result in a simple set of information being passed to the template file when it is processed.

The logs will show how the main action is invoked.

These would show how the additional objects are passed

**********RulesScript is...********
if (bCond)
{
AssignedUser = 4;
AssignedChannel = 1;
CaseTracker();
}
**********End of RulesScript.****

It is however possible to add other RuleSets that can conditionally be applied when the email is processed and these additional Rules would invoke alternative main action functions.

These additional rules look for different conditions within the returned objects.

The mail manager carries out searches on the person, company and user tables that check the inbound email address to see if it is already known in the system. The QueryObjects are passed to the scripts but these objects are also available to the check by the RuleSets.

In the example above the inbound email is check to see whether the company associated with the email address is of type 'Reseller'. If it is then the action create a communication is executed instead of the default main action.

The script functions are then invoked by passing to the template the following.

if ((!CompanyQuery.EOF) & & (CompanyQuery("comp_type")=="Reseller")
)
{
AssignedUser = 4;
AssignedChannel = 1;
CreateComm();
bCond=false;
}

if (bCond)
{
AssignedUser = 4;
AssignedChannel = 1;
CaseTracker();
}
**********End of RulesScript.****