Jira Scriptrunner - Grab Project Name within Behavior script

Michael
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.
July 3, 2024

Hi all,

I'm trying to create a behavior where I set values within a specific field based on which project is active within the "Create" screen.

How would I do this?

Currently, I've tried the following code: (I get a "null" value for the project name)

 

def projectField = getFieldById("project-field")

def projectFieldValue = projectField.getValue()

log.warn("value: $projectField")

def teamAffiliationField = getFieldById("customfield_11401")

//Defines which team affiliation values we want available when code below runs.

def teamAffiliationOptions = [

    "Project #1": ["option 1","option 2", "option 3"],

]

//Defines if grouping of team affiliation values activates depending on which project is currently selected.

if (teamAffiliationOptions[projectFieldValue]){

    teamAffiliationField.setFieldOptions(teamAffiliationOptions[projectFieldValue])

}

If anyone can let me I'd greatly appreciate it.

Thanks,

Mike

1 answer

1 accepted

0 votes
Answer accepted
Michael
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.
July 3, 2024

I've figured it out on my own.

Since I'm in the creation screen, I needed to use issuecontext.

Here is an example of the code used to pull in the project name:

//Pulls in project details
def
projectDetails = getIssueContext().getProjectObject()

//Grabs the project name from the project details previously pulled in.
def
projectName = projectDetails?.getName()

//Shows a log for what the value of the about project name is.
log.warn("value: $projectName")

def teamAffiliationField = getFieldById("customfield_11401")

//Defines which team affiliation values we want available when code below runs.
def teamAffiliationOptions = [
    "Project #1": ["option 1","option 2","option 3"],
]

//Defines if grouping of team affiliation values activates depending on which project is currently selected.
if (teamAffiliationOptions[projectName]){
    teamAffiliationField.setFieldOptions(teamAffiliationOptions[projectName])
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events