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

How to send custom email using scriptRunner

We want to send custom mail to that particular reporter with the attachments on the basis on Department ( Department is nothing but the text CF).

If reporter choose Letters – Address Proof within the Department then it should send the Address Proof file as an attachment.


2 answers

1 vote
Tarun Sapra Community Leader Feb 06, 2017

Since department is a text custom field. Just fetch the value of it 

cfValues['Department '] and check if it contains  "Letters – Address Proof " using contains() method.

IN the post-function "send custom email" option then you can select - "Include attachments" - "ALL" to send all attachments or if you want to filter out attachment in section

"Custom callback attachement" you can filter the attachements you want to send

like here -

HI @Tarun Sapra,

I have used the following script code

cfValues['Department']?.values()*.value == ['Letters', 'Address Proof']

and i got the below error

2017-02-06 11:12:41,255 ERROR [utils.ConditionUtils]: *************************************************************************************
2017-02-06 11:12:41,255 ERROR [utils.ConditionUtils]: Condition failed on issue: null, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail
groovy.lang.MissingMethodException: No signature of method: java.lang.String.values() is applicable for argument types: () values: []
Possible solutions: valueOf([C), valueOf(boolean), valueOf(char), valueOf(double), valueOf(float), valueOf(int)
2017-02-06 11:12:41,269 ERROR [utils.ConditionUtils]: Script follows:
cfValues['Department']?.values()*.value == ['Letters', 'Address Proof']
Tarun Sapra Community Leader Feb 06, 2017

You said in your question that it's a text CF and not a list, the script you wrote is for a list of values and not a single text field.


can you help me here to write Text CF script code. 

Tarun Sapra Community Leader Feb 06, 2017

cfValues['Department']?.contains(<your text>))

You can try the code first in the "script console", script runner plugin in the admin section has a script console and in that you can try the code. In the admin section of the plugin, search for "script console" and try the code there

As you told earlier i have been tested the below code

def cfValues
cfValues['Department'] == 'Letters-Address Proof'

but here i got the below error

Cannot get property 'Department' on null object

Tarun Sapra Community Leader Feb 06, 2017

cfValues is already available in workflow post-function and not in script console. I meant try to write contains function in the script console like

def value = "Letters Address proof testing"
//and now in your post-function you can replace the value with the cfValues['Department'], it's only meant to test out the string contains method.

if i use .contains() method then it gives me error like

can not find matching method

Tarun Sapra Community Leader Feb 06, 2017

Did you cast it to (String) ? First cast it to string and then call the method contains()

sorry i cant get it can you please write the code here


@Tarun Sapra can u help me out here to get it done.


Hi @Jamie Echlin (Adaptavist),

i am looking for the functionality that whenever the issue will be created by user then the emil should send to that user/reporter with one file.

The file will be same for all user/reporter so for this sending attachment file is i have to store this file some where else or else just need to specify that file name?

Where does the attachment come from? If it's from the current issue you can use a custom closure to define that:


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

2,193 views 10 4
Join discussion

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