Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Scriptrunner behaviours in create screen

Hi Community,

I need a behaviour, mapped to a issuetype in a project, so that when clicking on "Create" and select this project and issuetype, there are 3 custom fields that must be displayed in the screen, only if I select a specific value on other cascading custom field. I thought it was an easy thing, but it is not working. In Initialiser, I have put this code:

if (getActionName() in ["Create Issue", "Create"]) {

def fieldToHide1 = getFieldByName("Risk")
def fieldToHide2 = getFieldByName("Vul")
def fieldToHide3 = getFieldByName("Group")

fieldToHide1.setHidden(true)
fieldToHide2.setHidden(true)
fieldToHide3.setHidden(true)
fieldToHide1.setRequired(false)
fieldToHide2.setRequired(false)
fieldToHide4.setRequired(false)

def cfield = getFieldByName("Source")
Map mapValue = cfield.getValue() as Map


if (mapValue.get(1) == "SUR") {

fieldToHide1.setHidden(false)
fieldToHide2.setHidden(false)
fieldToHide3.setHidden(false)
fieldToHide1.setRequired(true)
fieldToHide2.setRequired(true)
fieldToHide3.setRequired(true)

}}

 

Please, I appreciate any help. Thanks!

 

1 answer

1 accepted

0 votes
Answer accepted

Hi, finally I got it!

I put this code in a server-side script for the specific field that makes the other change.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript

import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours fieldBehaviours

FormField field = getFieldById(getFieldChanged())
FormField fieldToHide1 = getFieldByName("Level")

if (getActionName() in ["Create Issue", "Create"]) {

fieldToHide1.setHidden(true)
fieldToHide1.setRequired(false)

def value = field.getValue() as List

if (value.toString().contains("high")) {

fieldToHide1.setHidden(false)
fieldToHide1.setRequired(true)

}
}

Suggest an answer

Log in or Sign up to answer
TAGS

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