How to create a Scripted Pre-Processing Task

Summary

The Scripted Task allows you to change message with a Velocity or ECMA Script script. 

The objective of the scripted task is to modify the message using a programmatic script, before running the standard JEMHCloud process. Even though Velocity is a template language designed to render UI, Emails, etc. it can be used to modify objects programmatically including the message.

Please note this is an advance feature and minimal programming skill is necessary.

How to use

  1. Once enabled, select the language in which you wish to write your script:

Velocity is deprecated, consider Javascript as the default, see subpage for examples

  1. Add the custom script that performs the specific action (the example shown here uses a Velocity script):

  2. Select or create a Test Case to use when testing the script:

  3. Add a Test Script. This is used to validate the outcome of the test case when the script has ran and must be written in the same language as the custom script:

     

  4. Press Validate to test the script. Any issues will be displayed explaining why the script failed to execute, underneath the script where the issues occurred:

  5. Make the relevant changes and then press Save.

  6. This script will then be used to modify incoming messages which are mapped to the Profile, before running the standard JEMHCloud process.

Adding a Test Case

A Test Case can be added by either creating your own email within the Test Case box or by selecting an existing Test Case from the Load Test Case list.

Using the Test Script

A way to verify that your email is being modified as expected is creating a Test Script that tests your main script. The test script will assert how the test case email looks after your script is executed against it. The test script is composed of a list of assertions. An assertion is a condition that needs to be true in order to pass.

You can test the script before saving by pressing the validate button. This will allow you to solve any issues before saving the change. If you attempt to save a script which contains issues, these issues will be reported and you will not be able to save your script until you have resolved them.

It's highly recommended to test your script by adding many assertions to verify it works properly. If an assertion fails, the error below the script editor will show you the line and column number in the script that is failing. The presence of a Test Script is required.

Test Script examples

For Velocity examples, see Velocity Scripted Pre-Processing Examples.

For ECMA Script examples, see ECMA Script Scripted Pre-Processing Examples.