Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner Behaviour: how do I hide custom field in Edit screen based on resolution value?

Sabine Van Regenmortel
Contributor
August 3, 2022

Hi,

We use resolution value Abort (ID 3) accompanied with a custom field Abort Why.
This is handled in a workflow transition. But still users must be able to modify it after the transition in the Edit screen.

Therefore I only want the Abort Why field to appear when resolution = 'Abort'.

I started by this behaviour with groovy script by googling and copy pasting.
It is a server side script on the custom field Abort Why.

It doesn't work. Only the hiding works, but not the resolution condition.

import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.ResolutionManager

def resolutionManager = ComponentAccessor.getComponent(ResolutionManager)

@BaseScript FieldBehaviours fieldBehaviours

def resolution = getFieldById("resolution")
def resolutionValue = resolution.formValue.toString()
def abortwhy = getFieldById("customfield_10111")


abortwhy.hidden = true

if (resolutionValue == "3" ) {
abortwhy.hidden = false
}

Thanks in advance.

1 answer

0 votes
Aditya Sastry
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.
August 3, 2022

Hi,

Try the below and let me know

 

if (resolutionValue == "Abort" ) {

. If it works, please mark the answer as accepted.

 

Thanks,

Aditya Sastry 

Sabine Van Regenmortel
Contributor
August 3, 2022

Hi,

Thanks but unfortunately, I tried that in the first place and it didn't work.

Aditya Sastry
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.
August 3, 2022

Hi Sabine,

I tried the below code in my instance and it worked. can you please check?

 


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


def AbortRelease = getFieldByName("Abort Why")

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

AbortRelease.setHidden(true)

if(resolution.name == "Abort")

{
AbortRelease.setHidden(false)
}
else
{
AbortRelease.setHidden(true)
}

 Thanks,

Aditya 

Like Sabine Van Regenmortel likes this
Aditya Sastry
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.
August 3, 2022

@Sabine Van Regenmortel did it work for you? If yes, please mark the answer as accepted.

Like Sabine Van Regenmortel likes this
Sabine Van Regenmortel
Contributor
August 3, 2022

Hi Aditya,

Thanks again for the effort. I would like to accept your resolution.
However, the script shows a green bullet but unfortunately it doesn't work.
It even doesn't hide the field in any case.

I both set it on field Resolution and Abort Why. Without initializer.
And also only on initializer.

Is your Abort Why field a radio button field? On which field did you set the script?

Thanks,
Sabine

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22.6
TAGS
AUG Leaders

Atlassian Community Events