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

This widget could not be displayed.

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

This widget could not be displayed.

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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

536 views 3 19
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