JIRA doesn't recognize email when field "Reporter" is set by script.

Gerda Zandersone January 26, 2015

We are working on projects were issues can be created via email or by assignee in name of reporter. So we have situation that we need to be able set reporter value based on project role (as JIRA default reporter doesn't have filter possibility on this).
So I have created script for post-function on "Create issue" transition (using new option to not create groovy file, but putting code in field "inline script")

def componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
CustomField reporter = customFieldManager.getCustomFieldObjectByName('Reporter');

if (issue.getCustomFieldValue(reporter) != null ){
    def cf = issue.getCustomFieldValue(reporter).getDisplayName()
	issue.setReporterId(cf)
}
issue.store()

And so far so good, everything seems to work, issue is created, JIRA default field "Reporter" value is taken from custom field BUT...
on this transition we also are using "send custom email" and here we have trouble, because JIRA doesn't recognize "Reporter" email.
And strange this situation is because in this email  what we are sending we have value " <% out << issue.reporter?.displayName %> " and here everything is fine and name is shown correctly.

So the question and HUGE problem here is - why JIRA doesn't recognize "Reporter" email? 

1 answer

1 accepted

1 vote
Answer accepted
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.
January 26, 2015

You should be setting reporter to the name, not the displayName.

def cf = issue.getCustomFieldValue(reporter).name
issue.setReporterId(cf)
Gerda Zandersone January 26, 2015

So simply solution! Thanks!!!

Vivek Janjrukiya November 30, 2016

I am also facing an issue with reporter condition. 

where i need to check reporter of the issue before script add user into request participant field and i am getting error:  please help to get it work... 

thanks in advanced !!

 

2016-11-30 15:30:10,199 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************

2016-11-30 15:30:10,199 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SS-915, actionId: 11, file: <inline script>
java.lang.NullPointerException
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
at com.atlassian.jira.issue.Issue$getCustomFieldValue$1.call(Unknown Source)
at Script757.run(Script757.groovy:33)

And here is the script: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserUtil()
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_17806")
def getUsersAsArray = 
{
    def users = ["pravin.mori"]
    ArrayList&lt;ApplicationUser&gt; userList = new ArrayList&lt;ApplicationUser&gt;()
    users.each 
    {
        def user = userManager.getUserByName(it)
        if(user)
        { 
          userList.add(user) 
        }
    }
    return userList
}
 
CustomField reporter = customFieldManager.getCustomFieldObjectByName('Reporter')
if (issue.getCustomFieldValue(reporter) == "vivek.janjrukiya")
{
MutableIssue myIssue = issue
ArrayList&lt;ApplicationUser&gt; applicationUsers = getUsersAsArray()
myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers)
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events