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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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.

0 votes
Leo Community Leader 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.

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;

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

175 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you