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!
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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.