How to send custom email using scriptRunner

Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2017

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 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.

Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2017

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 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.

 

Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2017

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

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 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

Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2017

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 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.
Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2017

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

can not find matching method

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2017

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

Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2017

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

 

Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2017

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

 

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 12, 2017
Yogesh Mude[Jira]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 13, 2017

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?

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2017

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