How to show Issue Links based on Resolution selection

Jennifer Smith April 19, 2021

What I would like to do:
On a workflow transition screen, expose Issue Links only if the Resolution selected is "Duplicate".

I've been trying to do this with a ScriptRunner Behaviour on the Resolution field. What I have right now hides the Issue Links fields on the correct screen, but it doesn't show them on the Resolution selection.

I don't have a background in Groovy/Java and cobbled this together from googling, so this might be something basic? It's not throwing any errors or warnings when I set up the Behaviour.

What isn't working:

import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def issueLinkType = getFieldById("issuelinks-linktype").setFormValue("duplicates")
def issueLinkValue = getFieldById("issuelinks-issues")
def resolutionValue = getFieldById(RESOLUTION).getValue()
final String screenName = 'Resolution and Assignee'


if (fieldScreen.name == screenName) {
if (resolutionValue == "Duplicate") {
issueLinkType.setHidden(false)
issueLinkValue.setHidden(false)
}
else {
issueLinkType.setHidden(true)
issueLinkValue.setHidden(true)
}
}

 

1 answer

1 accepted

3 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 19, 2021

Hi @Jennifer Smith,

For your requirement, you will need to modify your code slightly. 

First, when you invoke the resolution field, since it is a system field, it should be in lower case, i.e. instead of def resolution = getFieldById("RESOLUTION"), you should use def resolution = getFieldById("resolution") else the behaviour won't take effect.

The second point, instead of using value / getValue() from the Resolution field, you should use formValue / getFormValue().

Below is a print screen from where you can get the details of the values you should use:-

screenshot1.png

When you inspect the element with your browser, you will notice the field id for the Resolution field in lower case, and also, you can see the form value that is used as highlighted in the print screen above.

Below is a working sample code for your reference:-

import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours

@BaseScript FieldBehaviours fieldBehaviours

def issueLinkType = getFieldById("issuelinks-linktype")
issueLinkType.formValue = "duplicates"

def issueLinkValue = getFieldById("issuelinks-issues")
def resolution = getFieldById("resolution")

def resolutionValue = resolution.formValue.toString()
def screenName = "Mark as Done"

issueLinkType.hidden = true
issueLinkValue.hidden = true


if (resolutionValue == "10002" && actionName == screenName) {
issueLinkType.hidden = false
issueLinkValue.hidden = false
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

So in this example, when the dialog first appears, the Linked Issues option will be hidden.  Only when the Resolution list is updated to Duplicate will the Linked Issues option be visible.

Below is a print screen of the Behaviour configuration that I have tested with:-

behaviour_config.png

I hope this helps to solve your question :)

 

Thank you and Kind Regards,

Ram

Jennifer Smith April 20, 2021

THANK YOU!  This is a great answer, I really appreciate the suggestion to use browser dev tools to get the correct names.

One further note for anyone looking at this solution: it's responding to the name of the workflow button/display name of the screen, not the name of the screen in the screen configuration.

In my case, the name of the screen in the screen configuration is "Resolution and Assignee" but the display name that should be used in the script is "To Solved".

Suggest an answer

Log in or Sign up to answer