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

Karin Stevenson December 18, 2017

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 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 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

Karin Stevenson December 18, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 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)
}
Karin Stevenson December 19, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2017

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

Karin Stevenson December 19, 2017

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2017

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

Karin Stevenson December 19, 2017

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.

zhangqian04 June 1, 2020

same problem,please , how to resolute?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events