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

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

Karin Stevenson Dec 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 [cPrime] Community Leader 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

Karin Stevenson Dec 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 [cPrime] Community Leader 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)
}
Karin Stevenson Dec 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 [cPrime] Community Leader Dec 19, 2017

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

Karin Stevenson Dec 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 [cPrime] Community Leader Dec 19, 2017

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

Karin Stevenson Dec 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.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar alert! An IT Admin's Guide to Securing Collaboration at Scale

Hello, Atlassian Community! My name is Dave Meyer and I'm a Principal Product Manager at Atlassian. I wanted to give this community a heads up about an upcoming Webinar that might be of interest...

186 views 2 7
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