Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to prepopulate component field on create issue with scriptrunner behaviour

Peter Brodt September 9, 2022 edited

Can anyone provide a code snippet how to prepopulate the compontent field on create issue.

Adding templates to description fields works fine but a slightly adapted code for components does not work.

def comp = getFieldById("component")
def componentValue = "myComponent"
if (!comp.formValue) {
    comp.setFormValue(componentValue)
}
Any help is welcome
Peter

2 answers

2 accepted

1 vote
Answer accepted
Olly von Fay-Siebenburgen _ScriptRunner_
Contributor
September 9, 2022 edited

Hi Peter, 

This is Olly from Adaptavist's ScriptRunner Support!

The reason this isn't working, is because you are using underlyingIssue on Create, which doesn't work due to underlyingIssue being null on Issue Creation.

To achieve your requirement, you simply need to:

1. Ensure that the Component you want to add to the Issue with the Behaviour already exists.

2. Add the following code to the Initialiser:

//check if the Issue operation is Create
if
(actionName.equals("Create") ){

//retrieve the Component field, and populate with an existing Component
getFieldByName("Component/s").setFormValue("Example Component")

}

Hope this answers your question!

Thanks,

Olly

Peter Brodt September 9, 2022

Hi Olly

saw your comment too late and got it working myself. Nevertheless your background information is useful for the future.

Thanks a lot,

Peter

0 votes
Answer accepted
Peter Brodt September 9, 2022

The id for Component/s is "components"

 

def comp = getFieldById("components")


if (!comp.formValue) {
    comp.setFormValue("my component")
}

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Apps & Integrations Events