How to use Script Pre-Proc Task
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.
Pre-Processing Scope : Headers Only
Pre-processing only currently applies to Headers, not the body content, owing to the encoding complexities therein. If this is of interest, please reach out to support@thepluginpeople.com.
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.
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:
Affected Headers will show changes and additions:
Preview Context
This section is to explain what context keys are in the Script Pre-Processing task. Also explains what they are used for when making a script.
Currently three of the context keys are not working and are showing a console error. The three context key’s that are not working are Body, Subject and Related Issue.
Key | Class | Description |
---|---|---|
allAddresses | Array of all addresses in the email | |
baseUrl | Jira application URL. For example | |
bccAddresses | Array of all addresses in Bcc header in the email | |
body | Email content from the body of the email | |
ccAddresses | Array of addresses from the Cc header in the email | |
commentManager | Creates or removes Jira comments in the given Issue | |
context | Map of all context keys and all related context items | |
customFieldManager | Manages Custom fields and their values | |
fromAddress | Sender address of the email | |
groupManager | com.atlassian.jira.security.groups.RequestCachingGroupManager | Manages Atlassian’s groups and it’s members |
headerBeans | Header values from the email for example the Sender address and subject | |
issueLinkService | Creates Issue links between Jira issues | |
issueManager | com.atlassian.jira.issue.managers.RequestCachingIssueManager | Provides a number of methods for managing Jira Issues |
jemhUtils | com.javahollic.jira.emh.service.DefaultJEMHVelocityContextUtils | Provides a range of scripting utils including managed of headers shown on this page |
jemhVersion | The installed version of JEMH | |
log | Allows output into the JEMH log | |
message | The Email being processed | |
projectRoleManager | Manages the project roles of the sender | |
relatedIssue | The Issue that is being commented on (null if creating a new Issue) | |
remoteIssueLinkService | com.atlassian.jira.bc.issue.link.DefaultRemoteIssueLinkService | Creates Remote Issue Links that are used in external for example in a third party helpdesk |
searchService | Provides functionality related to searching in Jira using JQL. For example query string generation, parsing and validation
| |
senderUser | The Jira User associated to the From address | |
subject | The subject of the email | |
toAddresses | Array of all addresses in the To header of the email | |
userManager | Manages Jira Users on the instance | |
userPropertyManager | Manages all of the Property sets that are associated with Jira users | |
userSearchService | com.atlassian.jira.bc.user.search.DefaultUserPickerSearchService | Provides search functionality for Jira User e.g. |
watcherManager | Allows watches to be added/removed from the Jira Issue |
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:
|
Inserting new addresses into an existing Header
This example will alter the existing To address header, and will insert a new recipient into the To header:
|
Adding New Headers
This example will add the Bcc address header, with the provided values:
|
Use Auditing to see the post-change email content
Once the mail is changed you can download both the original mail, and the Edited mail:
API Reference
$jemhUtils == http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/3.3.80/com/javahollic/jira/emh/api/IJEMHVelocityContextUtils.html
$headeBeans == https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
preProcHeader class == http://ppl-docs.s3-website-us-east-1.amazonaws.com/JEMH/3.3.80/com/javahollic/jira/emh/api/preproc/PreProcHeaderBean.html
Methods used to Alter Headers
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: |
jemhUtils.updatePreProcHeader() | Updating To/Cc/Bcc/From/Delivered-To Header Values | Updating the Sender From address: |
headerBeans.remove(“cc”) | Removing Headers | Removing unwanted Cc address: |
jemhUtils.createInternetAddress(“nn”) | Creating a new Recipient to add to Header | Inserting a Bcc header: |
aHeaderBean.getOriginalVal() | Non-Recipient Header values | Retrieving the Subject Header:
|
aHeaderBean.setUpdatedVal(“nnnn”) | Non-Recipient Header values | Changing the Subject Header: |