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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,556,259
Community Members
 
Community Events
184
Community Groups

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

Edited

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

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.
Nov 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

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.  

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.
Nov 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.

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events