Global On-Edit Scripts

On-Edit Validator

Executed during validation phase when a user submits Issue Edit form or changes a field.

Context

VariableDescription
resultResult of validation; boolean value, default value is True
invalid_fields

PyDictionary(), empty by default; should be used like this:
invalid_fields["assignee"] = "message" or
invalid_fields["customfield_NNNNN"] = "message" where NNNNN is a custom field ID

description

A general message shown to the user if validation failed
PyUnicode(), empty Unicode string by default

issue

current Issue object with fields modified according to the user input; may be None if previous validations failed

parameters

a map, containing edit form field values; each value is a Java array, even if is a single value field

updateType

Available in JssPro 3.0.2 and later.

The type of the originating event. May be one of the following:
'create', 'update', 'assign', 'transition', 'clone' (for JIRA 7.1.1 and later)

validationResult

Available in JssPro 3.0.2 and later.

com.atlassian.jira.bc.issue.IssueService.AssignValidationResult for 'assign'
com.atlassian.jira.bc.issue.IssueService.CreateValidationResult for 'create'
com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult for 'update'
com.atlassian.jira.bc.issue.IssueService.CloneValidationResult for 'clone'
com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult for workflow transitions ('transition')

logorg.apache.log4j.Logger

Sample On-Edit Validator Script

if "TEST" in issue.getSummary():
	result = False
	description = "TESTs are not allowed"
	invalid_fields["summary"] = "Please do not specify TEST here"

If you want to compare modified issue with an original one, you may get it via IssueManager. The following script does no allow to edit Summary field:

from com.atlassian.jira.component import ComponentAccessor
issue_manager = ComponentAccessor.getIssueManager()

original_issue = issue_manager.getIssueObject(issue.getKey())

if issue.getSummary() != original_issue.getSummary():
	result = False
	description = "You can not change Summary"
	invalid_fields["summary"] = "Please do not change me!"

On-Edit Post Function

This is executed on issue edit after a validation has succeeded, but before issue is saved. You may update issue fields here.

  • This script is not executed on issue transitions

Context

VariableDescription
issuecurrent MutableIssue object
logorg.apache.log4j.Logger


Sample On-Edit Post Function

if issue.getProjectObject().getKey() in ["DEV"]:
    if not "(Development)" in issue.getSummary():
        issue.setSummary(issue.getSummary() + " (Development)")


Tips and Tricks

On-edit scripts are global for a JIRA instance. This means that they are executed for any issue. If you need to distinguish issues by project, issue type, etc., you should do this manually in the script or use 'classifiers' routines shipped with JssPro:

if issue.getProjectObject().getKey() in ["PM", "DEV"]:
	# do something
	pass