Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I Call a User Defined method from a post function?

Jeff Abbott December 25, 2020

I have a user defined function in a groovy script I keep in the Script Editor file list that I want to call from post function scripts also stored in the Script Editor list. My objective is to maintain one copy of the function that can be used across scripts (post functions).  I have included the method's declaration to simplify the discussion.

def TransitionLinkedIssues(com.atlassian.jira.issue.Issue issue, String targetLinkTypeName, String targetCategoryName, String targetTransitionName) {

...

}

2 answers

1 accepted

0 votes
Answer accepted
Manuel Alejandro Bastardo December 28, 2020

Hi @Jeff Abbott 

You should create a folder in the jira directory: "Scripts" and store the scripts there.

Then in the groovy using  the postfunctions or other you can call the function from using in the script.

import util. <your_groovy_name>
// and then call your function or method
<your_groovy_name> .functionName ()

I hope it helps you, you can find the documentation in Script Roots 

1 vote
Tom Lister
Community Champion
January 4, 2021

Hi @Jeff Abbott 

we store our util classes in Script Editor

image.png

Then access them from other other scripts

e.g. this is a workflow post function using the above

 

import com.cheil.retail.ShoptectConstants
import com.cheil.retail.ShoptectSubTaskHandler
import org.apache.log4j.Logger

def logit = Logger.getLogger("com.cheil.eu.logging")

ShoptectSubTaskHandler handler = new ShoptectSubTaskHandler(issue)
logit.info(handler)
handler.createSubTasks()

Suggest an answer

Log in or Sign up to answer