Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner for Jira Cloud - Send email when a custom field gets a certain value

Sigrid Kviteberg August 4, 2022

I am a Beginner in Script runner: 

I would like an email to be sent to the Reporter in the Jira issue automatically if a custom field is set to a certain value. 

E.g. If the Service Desk agent finds that the issue is not in-compliance with data privacy they will set a custom field to "Not in compliance". 

If this happens we would like a predefined email template to be sent out to the user in the reporter field. 

Link to a similar example, or just a detailed how-to is appreciated :-) 

Thanks!

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 5, 2022

Hi @Sigrid Kviteberg  As you are using JIRA Cloud, Using Project Automation you can easily setup Mail notification to Reporter based on Custom field value. 

If you still need Script runner, then try below code :- 

I tested code in Script Runner post function "Send Notification", 

Condition :- 

package com.adaptavist.sr.cloud.samples.events

//define custom field ID from the field where you want to get the value of
def customFieldName = 'customfield_10029'

//create API request to get custom field value
def result = get("/rest/api/2/issue/${issue.key}?fields=${customFieldName}")
.header('Content-Type', 'application/json')
.asObject(Map)

if (result.status == 200) {
result.body.fields[customFieldName].value.toString() == "100.0"
} else {
return "Error retrieving issue ${result}"
}

Message :- 

 

"""Dear ${issue.fields.assignee?.displayName},

The ${issue.fields.issuetype.name} ${issue.key} with priority ${issue.fields.priority?.name} has been assigned to you.

Description: ${issue.fields.description}


Regards,
${issue.fields.reporter?.displayName}"""

 

Thanks

Sigrid Kviteberg August 5, 2022

Thanks @Vikrant Yadav . My issue with the automation is that it will check the field value and send an email, but the next time it is scheduled to run it will send a second mail if the issue has been updated in the meantime. 

I have also tried checking on a field value, but my only options are to send an email if the field value changes - I can not select to send an email for a specific value entered in a field, and I am looking for separate emails to be sent for different values in a field.

There might be another way in the automation, but I will try out your Scriptrunner anyway as I am sure it will be useful in other cases. 

Thank you! 

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 5, 2022

@Sigrid Kviteberg  In Project Automation , you can use "Field Value Change" Trigger type >> Apply Condition if customfield value = Not in compliance >> Action "Send custom email". It send email only when custom field value set to "Not in compliance". 

Sigrid Kviteberg August 5, 2022

@Vikrant Yadav .... I should have asked about this several days ago :-D 

THANK YOU!

Like Vikrant Yadav likes this
TAGS
AUG Leaders

Atlassian Community Events