Complicated case with a custom field of another field dependency, e-mail notifications etc

Hello all. I've checked a lot of posts, but in most cases it was 2013-2014 years and I wish there could be experienced people with 2017 best bractices.

So, I have pretty complicated case which I'll try to cut for 2 parts:

1) if a bug field 'Environment'(Select list, single choice) has a selection 'Production', field 'SD'(Number field) should appears and this field should be required. When 'SD' field got a number, and when a bug goes to one of 3 statuses 'One', 'Two', 'Three', there should appears two more custom fields named 'Fix'(text field) and 'TestCase'(text field) which should be required both, and also two more custom fields 'Version' and 'QF" which are not required both. 

2) when a bug reach one of those 3('One' ,'Two', 'Three') statuses, there should start an e-mail notifications for futher statuses until this bug will be closed. E-mail notifications should has a Subject with a number from 'SD' field(like, ##12345##), and also inside of a body of e-mail has the infortmation from few custom fields like 'Fix', 'TestCase', 'Version', 'QF'(example, Fix: yes we will fix it somehow; Version: 11; etc).


I'll be very glad if someone has any advices how this case can be configured in a best way and I'll be very thankful for any help.

Thanks in advance!

1 answer

1 accepted

1 vote
Answer accepted
Tarun Sapra Community Champion Aug 05, 2017

Both these scenarios can be achived using Script runner JIRA plugin.

1) For first case use Behaviour plugin, wherein you can modify one custom field based on the value of another.

Following things can be done


The behaviours functionality allows an administrator to create one more or behaviours. A behaviour defines how fields behave for issues in a given project or issue context. Some examples of behaviours are:

  • Making a field mandatory depending on other data entered on the issue screen (i.e during an issue creation or an issue transition)

  • Making a field read-only dependent on user role or group

  • Doing server-side validation of field data, before the issue screen is submitted

  • Setting a field value dependent on other issue screen data

Full docs here  -

You can also use Javascript to make a custom field mandatory based on value of other

The above steps use client side validation. But if you want some validation to perform after the user has *clicked* on create button then you need to put the logic in the "validation" phase of the create transition of the workflow and that configuration will be part of the workflow configuration in the backend.

2) For the second scenario , you can use the "send custom email" postfunction of the script runner plugin to send cutomized email for every workflow status

Hello Tarun and thank you for your answer!


So, I'm in the middle of point 1, but faced with a little problem - 

I've tried to edit the script from example of behaviour, like this:

import com.atlassian.jira.issue.fields.CustomField

def CustomField = getFieldById("customfield_10009")
def Custom2Field = getFieldById("customfield_11503")

def custom = CustomField.getValue() as Custom

if ( == "Production") {
else {


But I got an error like: Compilation failure: startup failed: Script1.groovy: 8: unable to resolve class Custom @ line 8, column 37. def custom = CustomField.getValue() as Custom ^ 1 error

I understand, that the problem with  

def custom = CustomField.getValue() as Custom

But I can't find what class I should write there instead of Custom? 


And one thing more - about Javascript for make a field mandaroty etc, I've tried it before I posted a case here, but I've also faced with similar problem - edit script exactly for a custom field and it didn't work at the end. So, anyway, it's not so important right now, and I'm better to know which class I should to fill in a behaviour part.

Thank you!

I couldn't find a class called "Custom" in the APi that explains the error, can you try  like the code given in this sample-

i.e. directly check for value form the customfield instead of using "as" andif it still complains try putting a cast to an String.

if (dropDown.getValue() == "a") {



Thanks again, Tarun! Seems I've finished first part successfully!


Now I'm in the middle of second part configuration. 

If it works for you, please accept/upvote the answer.

Tarun Sapra Community Champion Aug 08, 2017

Good to hear that you have finished the first part successully, let me know if you face any issues in the 2nd part.

Tarun, thank you very much for help!

It's my code below, maybe it will help someone.

Behaviour fields:

import com.atlassian.jira.issue.fields.CustomField

def CustomField = getFieldById("customfield_10009")
def Custom2Field = getFieldById("customfield_11507")
def Custom3Field = getFieldById("customfield_11504")
def Custom4Field = getFieldById("customfield_11505")

if (CustomField.getValue() == "Production") {

else {

 import com.atlassian.jira.issue.fields.CustomField

def Custom3Field = getFieldById("customfield_11504")

if (getActionName() == "TEST" || getDestinationStepName() == "Done") {
} else {


Custom send to mail postfunction script.

Condition and configuration:

issue.projectObject.key == 'PROJECT' == 'Bug'
cfValues['Environment']?.value == 'Production'


E-mail HTML template:

<br><a href="$baseUrl/browse/$issue.key">$baseUrl/browse/$issue.key</a></br>

<br>Status: ${}</br>

<br>$ $issue.key with priority <% out << issue.priority?.name %>.</br>

<br>Summary: ${issue.summary}</br>

<br>Description: ${issue.description}</br>

<br> ServiceDesk: <% out <<
) %></br>

<br> Solution description: <% out <<
issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Solution description")
) %></br>

<br> Test-case description: <% out <<
issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test-case description")
) %></br> 


Subject template:

##RE-<% out <<
) %>## $issue.key

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 14, 2019 in Jira

Updates to give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

535 views 1 14
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