How to prepopulate component field on create issue with scriptrunner behaviour

Peter Brodt September 9, 2022

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) {
Any help is welcome

2 answers

2 accepted

1 vote
Answer accepted

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
(actionName.equals("Create") ){

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


Hope this answers your question!



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,


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
AUG Leaders

Atlassian Community Events