Velocity Pre-Processing Task Examples

Velocity Script

When creating a Script you may need to use a specific method that will perform specific actions. These methods can be found by expanding the Velocity Context section. Here you will see some pages that contain methods that you may need to use. When you expand the Velocity Context you will also find links to Javadoc for the published Java classes to help guide you.

Script examples

Adding your mailbox email address

Script:

$taskUtils.getHeaderOrCreate($message, 'To').addValue('add.me.as.email.user@mycompany.com')

Test Script:

You can assert the test case after it is processed by your script, by using the following assert. You should see that the email will have two “to” addresses, the original email address and the one the script adds.

$assert.assertEquals('Fernando <fernando@mail.com>,add.me.as.email.user@mycompany.com', $taskUtils.getHeader($message, 'To').getValueAsCSV())

 

Removing the Date header

Script:

$taskUtils.getHeader($message, 'Date).remove()

Test Script:

The following assert will check whether a value is returned. The Test Script passes if the returned value is now Null.

 

Detecting a missing From address and adding it to the email

Script:

Test Script:

The following assert will check that the From address is now set correctly.

 

Replacing the From address

This example shows how to manipulate the From address, to detect one domain and swap it out for another.

Script:

Example Email:

Test Script:

Script Configuration:

Processing Report:

Here you can see the example mail processing report generated by JEMHC for our support project. A user would have been associated if it didn’t exist, in this case we’ve simply created a new portal user.

 

Extracting an address from the name part and setting it as the From address

If you are receiving emails that are sent from a system address with a personal part that contains the actual sender address, the script below will extract the actual sender address from the original personal part and will set this value as the sender of the email, so that it can be processed correctly.

Example Script:

Example Test Case:

Test Script:

Script Configuration:

Processing Report:

Here you can see the example mail processing report generated by JEMHC for this Test Case. A user would have been associated if it didn’t exist, in this case we’ve simply created a new portal user with the correct email address and name.

Removing Recipients if Combined Addresses Exceed 255 Characters:

If you are using the default email only user custom fields, you may hit the 255 character limit. Which can prevent comments/issues being created. One way around this is to use pre-processing script to remove all recipients if larger than 255 characters.

Example Script:

Example Test Case:

Test Script:

 

Script Configuration: