Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 32 Next »

(info) since 3.3.42

Please refer to the Pre-Processing Task page for setting up and configuring Pre-Processing Tasks: How To Use Pre-Processing Tasks

After enabling Script Task, return to the profile configuration page and select the edit (pen) icon for Script Task.

image-20240312-113239.png

Configuration

The edit icon launches the pre-proc script editor.

What each field means?

Script Type

All Script Engines and Languages installed that can process Scripts. For more information on adding new Scripting Engines, please see: Installing a Scripting runtime Engine like Groovy

Matching Headers

A CSV list of headers that can be processed and altered by the Script Pre-Processing task. This includes new headers you want to add.

Header Script

The Script that will be run as a Pre-Processing task. Using the “Preview HeaderScript” button will run the script using the provided values and displayed below.

Test Case Selector

A list of all Test Cases that are linked to the given Profile, allowing them to be evaluated and for changes to be seen at edit time (next).

Preview Header Script

Evaluates the Header Script against the selected Test Case. The result of the script test will be shown below the existing form.

Example:

Matching Headers:

subject,x-subject

Script:

 var subject = headerBeans.get('subject').getOriginalVal(); 
 var hdr = jemhUtils.addPreProcHeader("x-subject", "NEW "+subject); 
 print('new header: '+hdr.getUpdatedVal());
 headerBeans.put("x-subject", hdr); 

Console Output - displays the console result of the script, driven by the print('….') method:

image-20240312-113926.png

Affected Headers will show changes and additions:

image-20240312-114015.png

Changing Headers

Example Test Case

To test this feature out, create a new Test Case, using the following Test Case Content:

 

 

MIME-Version: 1.0
Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT)
Date: Sun, 19 Jun 2011 17:42:26 +1200
Message-ID: <BANLkTinB1mfSh+GwOXGNWoL4SyDvOpdBoQ@mail.gmail.com>
Subject: This is a starting email template, update as required
From: from@from.com
To: oldTo@oldTo.com, changeme@thiswontwork.com
cc: removeme@cc.com
Content-Type: text/plain; charset=UTF-8

some text 

Altering Existing Header Values

Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!

This example will alter the first recipient in the To address header, changing its value:

/*Edit Headers*/ 
if(headerBeans.get('to') != null){
  var toAddress = jemhUtils.getOriginalAddressees(headerBeans.get('to')); 
  print('To Address Header values:', toAddress); 
  var firstRecipient = toAddress.get(0);
  /*Set Address and Personal values of selected recipient*/
  firstRecipient.setPersonal("changed recipient");
  firstRecipient.setAddress("changed@changed.com");

  var updatedHeader = jemhUtils.updatePreProcHeader(toAddress, headerBeans.get('to')); 
  print(updatedHeader.getUpdatedVal()); 
  print(updatedHeader.getUpdatedVal()); 
  
  /*Replace Header with new value here*/ 
  headerBeans.replace("to", updatedHeader); 
}

 

Inserting new addresses into an existing Header

Any Headers you wish to alter must be in the Matching Headers csv, or they will not be processed!

This example will alter the existing To address header, and will insert a new recipient into the To header:

/*Edit Headers*/ 
if(headerBeans.get('to') != null){
  var toAddress = jemhUtils.getOriginalAddressees(headerBeans.get('to')); 
  print('To Address Header values:', toAddress); 
  
  /*create new address*/ 
  var newAddress = jemhUtils.createInternetAddress('new', 'new@new.com'); 
  /*adding new address to To header*/
  toAddress.add(newAddress); 
  var updatedHeader = jemhUtils.updatePreProcHeader(toAddress, headerBeans.get('to')); 
  print(updatedHeader.getUpdatedVal()); 
  print(updatedHeader.getUpdatedVal()); 
  
  /*Replace Header with new value here*/ 
  headerBeans.replace("to", updatedHeader); 
}

 

Adding New Headers

Any new Headers you wish to add must be listed the “Matching Headers” csv, or they will not be processed!

This example will add the Bcc address header, with the provided values:

/* Adding a header */ 
var bccHeader = jemhUtils.addPreProcHeader('bcc', 'newBcc@newBcc.com'); 
if(bccHeader != null){ 
  headerBeans.replace('bcc', bccHeader); 
  print(headerBeans.get('bcc')); 
} 

 

API Reference

Methods used to Alter Headers

headerBeans expects Lower case key, i.e. ‘subject’, ‘content-type’, etc.

Method

Used for

Example

jemhUtils.getOriginalAddressees()

Retrieving To/Cc/Bcc/From/Delivered-To Header Values

Retrieving addresses from a specific header to compare against or edit:

var returnedAddressees = jemhUtils.getOriginalAddressees(headerBeans.get('to'));

jemhUtils.updatePreProcHeader()

Updating To/Cc/Bcc/From/Delivered-To Header Values

Updating the Sender From address:

jemhUtils.updatePreProcHeader(editedAddressees, headerBeans.get('from'))

/* OR non recipient example */
jemhUtils.updatePreProcHeader(editedValue, headerBeans.get('subject'));

headerBeans.remove(“cc”)

Removing Headers

Removing unwanted Cc address:

headerBeans.remove('cc');

jemhUtils.createInternetAddress(“nn”)

Creating a new Recipient to add to Header

Inserting a Bcc header:

/*Remember to add Bcc into Matching Headers*/

aHeaderBean.getOriginalVal()

Non-Recipient Header values

Retrieving the Subject Header:

/*Remember to add Subject into Matching Headers*/
var subject = headerBeans.get('subject').getOriginalVal());

aHeaderBean.setUpdatedVal(“nnnn”)

Non-Recipient Header values

Changing the Subject Header:

/*Remember to add Subject into Matching Headers*/
headerBeans.get('subject').setUpdatedVal("This is the new Subject value");

Body Script

We are currently gathering interest in this Feature. Please see JEMH-7508 for updates.

  • No labels