Change the EventID or Ignore an Event

 Since JEMH v1.8.18

Summary

JEMH provides the ability to control the events that its Event Listener detects. Events can be ignored, replaced or added to in addition. This config happens at the Project Mapping level, so no per-template changes are needed. If per-event changes are required, the templates must be updated, see:

Approach

The Event Listener Project Mappings have a Velocity script field which allows logic to be coded that could drive a change in how the event is handled.

The script is evaluated like any other template in JEMH, the difference is that the output of the render process goes nowhere except into the JEMH LOG, so is the perfect place for debugging:

Velocity context

The context available to the script is the generic one, shown on the JEMH > TemplateSet page.  In addition there are some new values available:

Reference

Description

Link for API methods

Reference

Description

Link for API methods

$issueEvent

The issue event that has been fired by Jira.

IssueEvent Jira API Docs

$issue

The Jira issue that the event is related to. Note that this is not the same $issue reference used in Template Sets, this the real Issue object.

Issue Jira API Docs

$comment

If a comment was made as part of the event this reference represents that comment.

Comment Jira API Docs

$result

The JEMH result object that is used to instruct JEMH on what to do with the event.

See below

Result Bean methods

Method

Parameters

Example usage

Method

Parameters

Example usage



setIgnoreEvent(boolean ignore)



ignore - whether or not the event should be ignored. Set to true to ignore, false otherwise.

$result.setIgnoreEvent(true)



setReason(String reason)



reason - a text string containing the reason for the event change or ignore.  This is optional and is for providing information in log files.

$result.setReason('Its a trivial issue, save the people from this notification')



setTargetEventId(int targetEventId)



targetEventId - the integer ID of the event to set as the target event. The target is event is for use with the setEventBroadcastMethod method.

$result.setTargetEventId(12356)





method - a String representing the broadcast method to use:

  • "useDerivedEventInstead" will replace the event with the event type set via setTargetEventId(int targetEventId)

  • "useDerivedEventAsWell" will notify for both the original event type and the new event type that has been set

A method must be set in order for a different event type ID to be used.

$result.setEventBroadcastMethod('useDerivedEventInstead')





ignoreAtts - whether or not attachments that have already been sent should be ignored or not for the event.  Set to true to ignore, false otherwise.

$result.setIgnoreUnsentAttachments(true)

Ignoring an event

In this contrived example, an issue is commented on, and that issue has a priority of 'Lowest', the script for JIRA users will cause those events to be filtered.

This is the content of the JIRA user notification part of an Event Listener Project mapping for the 'TEST' project:

Script being edited in Event Listener

Script being viewed in Event Listener

Script being edited in Event Listener

Script being viewed in Event Listener

 

 

The result of a comment on an issue with 'Lowest' priority' can be seen, First the NON-JIRA User Notifier runs, showing the velocity pos-processing of the non-JIRA script (which here was just static text and didn't affect the $result:  "Non JIRA script here".

The JIRA User notifications are where the above script is run, it refers the issue Key, the Event#, ind indicates that after evaluation, the $result is to ignoreEvent.  The post rendered output from the script shows the static text embedded in the template, which can be used for debug:

 

Blocking all JSM Internal Comment notifications

Log output:

Replacing an event with another

Now, a slight change in the script:



Log output, showing how system default templates are located for event 13, rather than the input event 6.



Adding an event in addition to the original

A minor variation of the above to cause notifications to be sent based on BOTH event types:

Log output shows:



Checking if an attachment was added

Events don't refer attachments, but JEMH can provide support for determining some things through a script helper utility:

Log output, for an attachment added

Checking the value of a custom field

You want to ignore an event if a custom field has a certain value.

The following example script checks to see if an event is an Issue Created event and whether or not a custom field has the value Email. If both checks are true then the event will be ignored else an notification will be sent.

Log output