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

On Create Issue: set the Description Based on the Component (like a Template) - Scriptrunner

Shannon Davis November 17, 2020

I am trying to use ScriptRunner behaviors to set up a default description based on the selected component.  I have configured the Behavior and associated it to a Project and Issue Type.  

Initially I was using the Initializer as in the example, but that sets a Default Description before the Component is set.

So I moved my script to the Component field, assuming that when I select a Component, the description will update.  That is NOT what is happening.  The script doesn't appear to run when the component field is changed.

Questions:

Is this possible? (on the Create Issue screen, having the Description update based on the Component selection)

If possible, is this the correct way to accomplish?

If possible, how does this script look to you?  

scriptrunner_componentsetdescription.jpg

3 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Shannon Davis November 19, 2020

Thank you, Leo. You got me closer by realizing I needed to get the field value not the underlying issue value.

Also, from another source after much searching, I figured out how to get the first component!  This was the key, defining the value returned from component as a List.  Then I could reference the first one on the list!

def componentField = getFieldById(getFieldChanged());
def components = componentField.getValue() as List<ProjectComponent>

def comp = components.first().name;
0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 18, 2020

Hi @Shannon Davis

I believe the script does run but it sets description to default value always

if so, that is due to your comparison method, you are using "comp" variable in which stored component/s of the current issue(usually returns from DB value) but that's not having any value yet

rather you should use "comps" variable and get first value from list and do the comparison

hope this helps

 

BR,

Leo

Shannon Davis November 19, 2020

Thanks!  I was following a lot of examples - I will try the comps variable instead.

It actually doesn't set anything since I moved it from Initializer to the Component field.  

Shannon Davis November 19, 2020

I am not that familiar with this programming language but I can't seem to access the first element of the array doing this:

def componentField = getFieldById("components");
componentField.setRequired(true);
def comps = componentField.getValue();

//get the values of the component field
def comp = comps[0].getName();

//to try to get the name of the first element

 

It doesn't allow me to reference the first element of comps.

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 18, 2020

Hi @Shannon Davis I hope I can help you.

Are you sure the script is not executed at all? Did you try to add some logging to it? I suggest you to add following code to 2nd row

log.error("executing behaviours with default description")

Then you can check your server log file to find out whether it is executed or not.

Did it work for you when you added it to initializer? Based on your code, "Background Justification:" should be added to description field even without picked up component.

Shannon Davis November 19, 2020

It worked as the Initializer but since the component had not yet been selected, I wanted to move it to the component field.

Thanks for the tip on logging - I wasn't sure how to do that.

TAGS
AUG Leaders

Atlassian Community Events