Behaviour Question: Script not rerun when drop-down option is changed

I apologize if this is described somewhere and I've not found it.

I implemented a Behaviour script for setting the linked issue field to be mandatory if the selected Resolution option is "Duplicate". I set up a custom "Resolution with linked Issue" screen that's called during a transition to a step "Completed" that can be selected from All steps in the workflow.

It works fine the first time around after the screen is opened (as part of the transition). The default Resolution is Fixed and when the user changes that to Duplicate, the Linked Issue fields become mandatory. However, when the user changes the resolution values again, the linked issue fields are not set to "not required" as specified in the script.

It appears that the script is only executed after the screen is initially loaded but not if the user changes the Resolution again to something else. 

The script below is in the server side script for the field "Resolution", not the Initialiser script. I tried that as well but it didn't work at all.

Here is the detailed behavior: When the user initiates the transition that brings up the custom "Resolution with linked Issues" screen, the default Resolution is "Fixed". The fields for linked issues ares not mandatory, which is correct.

After I change the resolution to "Duplicate" the fields "Linked Issues" and "Issue" are set to become mandatory. Again, this is correct.

However, when I change the resolution to something else after selecting Duplicate, the linked issue fields *stay* mandatory in spite of the else clause in the script below.

Could somebody please provide guidance on why the script is ignoring the "else" clause when the Resolution is changed after the intial loading of the screen? 

Here is the code 

import com.atlassian.jira.issue.resolution.Resolution

def resolutionField = getFieldById("resolution")
def linksField = getFieldById("issuelinks")
def resolution = resolutionField.getValue() as Resolution

if (resolution.name == "Duplicate") {
linksField.setRequired(true)
linksField.setHidden(false)
}
else {
linksField.setRequired(false)
linksField.setHidden(false)
}

Thanks in advance for the help and advice!

Karin

1 answer

0 vote
Alexey Matveev Community Champion Dec 18, 2017

Hello,

It is important where you put the script. You need to add the field Resolution to your behaviour and add the initialize script for the field. I guess you put the script for the whole behaviour that is why it works only when you open the screen.

If you can not figure out where to attach the script kindly attach a screenshot of your behaviour configuration

Alexey, It appears that you're my Guardian Angel in this painful Jira setup for our team. Thank you so much for doing this.

I initially followed the instructions in this article: 

https://www.adaptavist.com/doco/display/SFJ/Use+Behaviours+to+include+a+link+to+duplicate+issues

It says to put the script into the initialiser function but that didn't do anything. I ended up putting the whole script into the server side script for the Resolution field itself which cases the problems described above.

I also just realized when I set the resolution to Duplicate and add a link I can't submit the form.  I'm about ready to throw in the towel :-(.

Here is the screenshot.

image.png

Screenshot of the script itself (located in the serverside for Resolution field:

 

 

 

image.png

Thanks so much for your help and patience with a Jira semi-novice.

Karin

Alexey Matveev Community Champion Dec 19, 2017

Your script must be like this

import com.atlassian.jira.issue.resolution.Resolution
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.issue.IssueConstant
def resolutionField = getFieldById(RESOLUTION)
def linksField = getFieldByName("issuelinks")
def resolution = resolutionField.getValue()
if (((IssueConstant) resolution).getName() == "Duplicate") {
linksField.setRequired(true)
linksField.setHidden(false)
}
else {
linksField.setRequired(false)
linksField.setHidden(false)
}

Thank you very much, Alexey! A last question: Do I put that into the Resolution field's server side script or as initialiser script?

Alexey Matveev Community Champion Dec 19, 2017

You put it into the Resolution field's server side script

Thanks, Alexey. Unfortunately, it doesn't work at all with getFieldByName("issuelinks")

And when I change that to getFieldbyId it works initially (it sets the issue link fields to mandatory when resolution "Duplicate" is selected). But I have the same problem I had yesterday that the issue link fields stay mandatory after I change the resolution from Duplicate to something else.

If the script ran again upon change of Resolution (as the Behaviour documentation says) it should set linksField.setRequired(false) but it doesn't. 

Thanks so much for trying to help me with my issues. I really appreciate it. 

My Best

Karin

Alexey Matveev Community Champion Dec 19, 2017

What is the issuelinks field? Is it a custom field you added? What type is it?

It's not a custom field. it's the functional element for the issue links. Here is a good description: https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/working-with-issuelinks.html#_setting_the_value

As I said, the script works correctly right after the screen is loaded. It's just not resetting the Required restriction when another value is chosen.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

849 views 2 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you