How do we make certain fields hidden on changing issue type using behaviours ?

Hi @Jamie Echlin [Adaptavist],

                                             Can you help me with code where the field would be issue type and based on changes to issue type, i would like to make certain fields hidden or vsisible using Script Runner Behaviour plugin.

Writing Behaviour on a field Issue Type

import com.atlassian.jira.component.ComponentAccessor

def issueTypeField = getFieldById(getFieldChanged())
def jpField = getFieldByName("JIRA Project")
def urlField = getFieldByName("GitLab URL")
def aurlField = getFieldByName("Additional URL's / Notes")
def selectedOption = issueTypeField.getValue() as String

if (selectedOption == "Story")
{
    urlField.setHidden(false)
    urlField.setRequired(true)
    aurlField.setHidden(false)
    aurlField.setRequired(true)
    jpField.setHidden(false)
    jpField.setRequired(true)
  
}
else
{
    urlField.setHidden(true)
    urlField.setRequired(false)
    aurlField.setHidden(true)
    aurlField.setRequired(false)
    jpField.setHidden(true)
    jpField.setRequired(false)
}

 

What am i writing wrong in the code. please help me with this.

Regards

Chander Inguva

2 answers

Hi Chander

I think you need the getIssueContext() to retrieve the issue type and the project for example

def projectKey = getIssueContext().getProjectObject().getKey()
def issueTypeName = getIssueContext().getIssueTypeObject().getName()

Regards

Hey @Thanos Batagiannis [Adaptavist],

                                       That worked like magic. 

I have created an Initialiser like below

def projectKey = getIssueContext().getProjectObject().getKey()
def issueTypeName = getIssueContext().getIssueType().getName()
def WSField = getFieldByName("Wiki Space Name")
def SKField = getFieldByName("Space Key")
def SAField = getFieldByName("Space Administrators")
if (issueTypeName == "Wiki Space Request")
{
    WSField.setHidden(false)
    WSField.setRequired(true)
    SKField.setHidden(false)
    SKField.setRequired(true)
    SAField.setHidden(false)
    SAField.setRequired(true)
}
else
 {
    WSField.setHidden(true)
    WSField.setRequired(false)
    SKField.setHidden(true)
    SKField.setRequired(false)
    SAField.setHidden(true)
    SAField.setRequired(false)
}

Thank You

Chander Inguva

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

412 views 0 3
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