Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,061
Community Members
 
Community Events
168
Community Groups

How to prepopulate component field on create issue with scriptrunner behaviour

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

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

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

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
Community showcase
Published in Apps & Integrations

Apps for Confluence you won't want to miss: RSVP for September's Appy Hours

Calling all collaborators and Confluence users! Our Appy Hours event on September 29th features 4 presenters demoing functionality to superpower Confluence. Don't miss learning about these apps i...

117 views 0 9
Read article

Atlassian Community Events