Forums

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

Call a function located in another file in Script editor to accesss some constant values

Mouna Hammoudi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2022

I am implementing a fragment with a REST endpoint and I am writing the condition as a script. I need to call a function from another class called Configuration_CreateMultipleSubtasks.groovy. 

 

Here is the structure of my files in the script editor 

Capture.PNG I need to call a function located in the file Configuration_CreateMultipleSubtasks.groovy. The latter file contains some constant values that I decided to store there. 

 

Here is the code for my condition Fragment_Condition_CreateMultipleSubtasks.groovy. I would like to call the function getSubTaskCreatorHashMap() which is located in another file given that this function stores some constant values.

 

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.security.plugin.ProjectPermissionKey

import com.atlassian.jira.plugin.webfragment.model.JiraHelper

import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks

import com.atlassian.jira.project.Project

import org.apache.log4j.Logger

def log = Logger.getLogger("atlassian-jira.log")

Configuration_CreateMultipleSubtasks conf= new Configuration_CreateMultipleSubtasks();

 def subTaskCreatorHashMap= conf.getSubTaskCreatorHashMap()

String projectKey1 = subTaskCreatorHashMap["projectKey"] ;

String issueTypeName1 =subTaskCreatorHashMap["issueTypeName"];

String projectKey = "PIE" ;

String issueTypeName ="Defect";

def val=jiraHelper.project?.key==projectKey  &&  issue.issueType.name==issueTypeName

log.warn("MOUNA CONDITION IS TRUE"+ projectKey1+" "+issueTypeName1)

return val

Obviously, my import is not working since I am not able to print projectKey1 and projejctKey2 in the code below.

 

 public  class Configuration_CreateMultipleSubtasks {

 

    static def getSubTaskCreatorHashMap(){

        def map = [itracCreatemultiplesubtasksIssueTypesId:5,

        itracCreatemultiplesubtasksProjectCategoriesID: [10011, 10200, 10220, 10230, 10240, 10670, 10170, 11170, 11270, 11870, 11871, 11872, 11873, 11874, 11875, 12470],

        itracCreatemultiplesubtasksProjectCategoriesURL: "http://itrac-sustservice.eur.ad.sag:5555/web/subtaskmgr/Login.jsp?iTrac=:1:&reporter=:2:",

        projectKey: "PIE",

        issueTypeName: "Defect"]

        return map

    }

}

1 answer

1 vote
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 2022

This import ...

import CreateMultipleSubtasks.Configuration_CreateMultipleSubtasks

... implies that your class file is stored in a path like <jira-home>/scripts/CreateMultipleSubtasks/Configuration_CreateMultipleSubtasks.groovy

Is that correct?

If not, then adjust the classpath to match the file path.

Also, be sure to define that path in your Jira startup parameter. Read more here

-Dplugin.resource.directories=${JIRA_HOME}/scripts

 Also, since you've defined your method as static, there is no need to instantiate.

You can just do this:

 def subTaskCreatorHashMap = Configuration_CreateMultipleSubtasks.subTaskCreatorHashMap

Suggest an answer

Log in or Sign up to answer