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

This widget could not be displayed.
Tarun Sapra Community Champion 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 - https://answers.atlassian.com/questions/18811112.

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)
	at Script42.run(Script42.groovy:1)
2017-02-06 11:12:41,269 ERROR [utils.ConditionUtils]: Script follows:
cfValues['Department']?.values()*.value == ['Letters', 'Address Proof']
Tarun Sapra Community Champion 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 Champion 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 Champion 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"
value.contains("Letters") 
//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 Champion 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 invoice.docs 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: https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_attachments_in_emails

 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Friday in Bitbucket

What is your #1 piece of advice to new users getting started using Bitbucket?

Hello Community! My name is Claire Maynard, and I’m a Product Marketing Manager on the Bitbucket team. I’m interested in hearing what advice or tips you have for new users getting started on ...

136 views 5 2
Join discussion

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