Browse Month

January 2023

Inbound Action Framework

Requirement

A new Incident is to be created on the basis of an incoming email. The fields in the new Incident are to be created with a defined template depending on a sender address. Sender A’s Incidents shall be created with template X and e-mails coming from address B shall be created with template Y and so on. Replies to existing incidents or forwarded emails shall not be considered.

With out-of-the-box functionality, this can be easily implemented. The only catch is that each additional email address that is added to the list requires development effort and has to wait until the next release before it can be used. An inbound framework shall implement this completely without development effort, so that changes can also be realized in production. The subject, e-mail body etc. shall be mapped to target fields as desired.

Solution

A new configuration table is created in which there is a field for the email address. This field is unique, so there can only be one entry for each configuration and email address. There is also a Name-Value-Pairs field for mapping email object properties to target fields.

Field Mapping

A Script Include is created, which takes over the task of checking whether there is a configuration entry for the incoming email and if so, creates a new record in the target table definied in the template. The mapping of the name-value pairs to the target record then can looks like this:

JavaScript
function map(email, targetGR){ // email variable from Inbound Action
var fieldMapping = JSON.parse(configGR['u_field_mapping'].toString());
    for (var key in fieldMapping) {
    var fieldsArray = fieldMapping[key].split(',');
        for (var field in fieldsArray) {
            targetGR[field] = email[key.valueOf()];
        }
    }
}

The variable configGR in the script stands for the GlideRecord in the configuration table, which defines which template should be used for which email address. The mapping shows that a property of the email object can be mapped to several comma-separated fields of the target table. The email object is the variable available in the inbound action in the script field, which is passed to the map() function in the script include.

The next step is to insert a reference field for table sys_template in the configuration table. This allows one to specify a different target table as incident and to assign values to other fields as required. Also here the advantage is that everything can be done on production and therefore can be implemented immediately.

IF Template

The script for creating a new record could look like this:

JavaScript
function createGR(){
    var newRec = new GlideRecord(this.configGR['u_template'].table);
    newRec.initialize();
    this.map(email, newRec);
    newRec.applyTemplate(this.configGR['u_template'].getDisplayValue());
    newRec.insert();
}

Finally, the scripts listed in the text are not complete examples, but are intended to illustrate the idea and the way forward, and most importantly, to reduce deployment effort as existing configurations change or new ones are added. There are cases where users or user groups from different countries and areas are offered different email addresses to report their issues. Each of these email addresses can be assigned to a specific service, assignment group etc. to speed up troubleshooting. With above illustrated solution reaction speed for business is increased and hence the user satisfaction.