I want to be able to send email notification on an update on a ticket when, along the assignee, I have also a custom user picker field called "Requirement Owner".
I dont know how to access the email field of that "Requirment Owner"
I started with this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def issueTypeName = event.issue.issueTypeObject.name
def customField = customFieldManager.getCustomFieldObjectByName("Requirement Owner")
if (issueTypeName == "Requirement" ) {
def emailAddress = issue.getCustomFieldValue(customField)?.get("1")?.value
log.warn("${event.issue.key}")
log.warn(event.issue.key)
if (emailAddress) {
def params = [
"issue" : event.issue,
(SendCustomEmail.FIELD_EMAIL_TEMPLATE) : "Issue ${event.issue.key} has been updated",
(SendCustomEmail.FIELD_EMAIL_SUBJECT_TEMPLATE): "New Issue Created ${event.issue.summary}",
(SendCustomEmail.FIELD_TO_ADDRESSES) : emailAddress,
(SendCustomEmail.FIELD_EMAIL_FORMAT) : "HTML"
]
def sendCustomEmail = new SendCustomEmail()
if (!sendCustomEmail.doValidate(params, false).hasAnyErrors()) {
sendCustomEmail.doScript(params)
}
}
}
Please help
Hi,
This is where you have a problem:
def emailAddress = issue.getCustomFieldValue(customField)?.get("1")?.value
Assuming your "Requirement Owner" is a single-userpicker type field, it's value is an ApplicationUser object.
With that in mind here's how you extract email address from ApplicationUser:
String emailAddress = issue.getCustomFieldValue(customField)?.getEmailAddress()
now the "issue" causes error as it is not recognized.
String emailAddress = <<<issue>>>.getCustomFieldValue(customField)?.getEmailAddress()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.