Workflow Scripts

Condition

Executed when a transition is being showed to a user.

Context

VariableDescription
result

Result of a condition script evaluation; boolean value, default value is True
Setting this to False hides a transition from the user

issuecurrent Issue object
logorg.apache.log4j.Logger
transientVarsA map containing all context data passed to the condition

Sample Condition Script

summary = issue.getSummary() # note that summary here is a python string, not Java String
result = summary.find('TEST') < 0 # find() returns -1 if string not found

# or simply in one string
result = not 'TEST' in issue.getSummary()

Be Careful

Although issue is actually a MutableIssue object, you can not change any issue data in a condition script.

Validator

Executed during validation of user input on a transition.

Context

VariableDescription
resultResult of a condition script evaluation; boolean value, default value is True
Setting this to False hides a transition from the user
invalid_fields

Field-related messages shown to the user if validation failed

PyDictionary(), empty map by default

description

A general message shown to the user if validation failed

PyUnicode(), empty Unicode string by default

issuecurrent Issue object with fields modified according to the user input
originalIssueoriginal (unmodified) Issue object
logorg.apache.log4j.Logger
transientVarsA map containing all context data passed to the validator

Sample Validator Script

In a validation script we use another two variables along with result to reports an error to the user: invalid_fields and description. See example:

result = False
description = 'General error description'
invalid_fields['summary'] = u'Error description for the Summary field'

This script unconditionally produces this message for every issue with that workflow:

Post Function

Executed before or after the issue is saved depending on post function position in the list. See screenshot below.

Context

VariableDescription
issuecurrent Issue object with fields modified according to the user input

log

org.apache.log4j.Logger
transientVarsA map containing all context data passed to post function

Sample Post Function Scripts

  1. If located before saving the issue, this script will increase due date by two days if it is set or set it in two days from today if not set. Python datetime routines are used. 

    from datetime import datetime, timedelta
    from java.sql import Timestamp
    import calendar
    
    duedate = issue.getDueDate() # this will be java.sql.Timestamp or None
    
    # convert java.sql.Timestamp into Python datetime
    duedate_py = datetime.fromtimestamp(duedate.getTime()/1000) if duedate else datetime.today()
    
    # add two days
    new_duedate_py = duedate_py + timedelta(2)
    
    # convert back into java.sql.Timestamp
    new_duedate = Timestamp(calendar.timegm(new_duedate_py.utctimetuple())*1000)
    
    issue.setDueDate(new_duedate)