How to populate fields on selection of other field on the creation of issue screen?

Teja April 20, 2016

We have a business need to create a JIRA Project that uses many fields (as most of our projects), but one of the items that we have a need for is a single-select field to require other fields to be required which varies depending on the option that is selected,

As an example:

Field is called 'JobRoles', which has 3 options in the drop down - QA, Engineering and Developer and is created as a single-Select field

If “QA” is selected we require that the 'QA Manager Approver ' (Single user Picker field) is populated. but not for Engineering

If Engineering is selected we required that the 'Senr Eng Approver' (Single user Picker field) is populated, but not for QA.

If Developer is selected just not require any approver.

Is there a way to do this as all I can find is to make the field required for all selections or required during the creation of issue...any ideas or options that anyone has encountered?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Kristian Walker _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 21, 2016

Hi Teju,

You can use the Behaviours module of the ScriptRunner add on to make fields required when a select list option is selected on the Create and Edit Screens.

I have attached an example script of how you can do this below.

import com.atlassian.jira.component.ComponentAccessor
// Get the Custom Field Manager

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// Get a pointer to my select list custom fields
def jobRole = getFieldByName("JobRoles")
def qaApprover = getFieldByName("QA Manager Approver")
def engApprover = getFieldByName("Senr Eng Approver")

// Get the value of the JobRoles field
def jobRoleVal = jobRole.getValue()

// if jobRole has the value of QA make the QA Manager Approver field required
if(jobRoleVal.toString() == "QA"){
  qaApprover.setRequired(true)  
}else{
    // If value unselected
    qaApprover.setRequired(false)
}

// if jobRole has the value of Engineer make the Senr Eng Approver field required
if(jobRoleVal.toString() == "Engineering"){
    engApprover.setRequired(true)
}else{
    // If value unselected
     engApprover.setRequired(false)
}

// if jobRole has the value of Developer display a message to say the developers do not require approval
if(jobRoleVal.toString() == "Developer"){
    jobRole.setHelpText("Developers do not require approval")
}else{
    // If value unselected
    jobRole.setHelpText("")
}

 

If you only wanted to make this behaviour fire on the Create screen then you could add the workflow used by the project as a guided workflow to the behaviour and add a condition to ensure the that the script only executes when the workflow action is Create. An example of what this looks like is shown in the screenshot below.

image2016-4-21 11:56:18.png

I hope this helps.

Thanks

Kristian

Teja April 21, 2016

Great..Thank you Kristian

TAGS
AUG Leaders

Atlassian Community Events