Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

email notification for update event on custom user picker

ofirgu@bezeqint.co.il January 15, 2019

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

1 answer

0 votes
Ivan Tovbin
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.
January 16, 2019

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()
ofirgu@bezeqint.co.il January 17, 2019

now the "issue" causes error as it is not recognized.

String emailAddress = <<<issue>>>.getCustomFieldValue(customField)?.getEmailAddress()

Suggest an answer

Log in or Sign up to answer