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?
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;
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.