User Tools

Site Tools


post_functions

This is an old revision of the document!


Post Functions

Post functions allow you to perform specific actions upon the transition. Following are some useful examples.

Add Comment on Transition

import com.atlassian.jira.component.ComponentAccessor
 
def commentManager = ComponentAccessor.getCommentManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
    commentManager.create(
        issue,
        currentUser,
        "This is my comment",
        false) 

Update Fix Version/s field with first Unreleased version if there isn't a version already there or give error message

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
 
def versionManager = ComponentAccessor.getVersionManager()
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectObjByKey(issue.projectObject.key)
def versions = versionManager.getVersions(project)
def firstUnreleasedFound = versions.find{! it.released}
 
if (issue.fixVersions.size() == 0){
	UserMessageUtil.success("I'm in the loop")
    if (firstUnreleasedFound) {    
		issue.setFixVersions([firstUnreleasedFound])
		issue.store()
	} else {
    	UserMessageUtil.error("MANUAL INTERVENTION REQUIRED!!! No Unreleased Fix Version Found. Please add a Fix Version manually to this ticket....")
	}    
}
post_functions.1515767030.txt.gz · Last modified: 2018/01/12 09:23 by pawel