Forums

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

Set a default value in component in creation Behaviour

BYA May 25, 2021

Hello, 

i want to set a default component "Example1" and "Example2" when I want to create a issue. i found this behaviour in Initialiser : 

import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.*

if (getActionName() != "Create Issue") {
return // not the initial action, so don't set default values
}

// set Components
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)
getFieldById(COMPONENTS).setFormValue(components.findAll { it.name in ["Example1","Example2"] }*.id)

 

But when i want to create a issue, the components field is not filled with the values "Example1" and "Example2":

Capture00004.PNG

Please can you help, is very urgent. 

Thanks community . 

Fayçal

PS : we already have a list of values in components field. 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
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.
May 25, 2021

Hi

 

Are your existing components spelled exactly like 

"Example1","Example2"

Have you reviewed the atlassian-jira.log file to see if there are any errors?

Add some logging and review the log files to get progress on your script's execution:

log.info "script is reporting the current screen as $actionName"

if (getActionName() != "Create Issue") {
return // not the initial action, so don't set default values
}
log.info "script is passed the action check"

// set Components
def projectComponentManager = ComponentAccessor.getProjectComponentManager()

def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)
log.info "script found components for currentproject: $components"

def mycomponents = components.findAll{it.name in ["Example1", "Example2"]}
log.info "script found my components: $myComponents"

getFieldById(COMPONENTS).setFormValue(components.findAll { it.name in ["Example1","Example2"] }*.id)
log.info "script applied my components to ${getFieldById(COMPONENTS)"
BYA May 26, 2021

It works thank you so much for your help 

BR

Fayçal

TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events