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

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

This widget could not be displayed.

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

def cf = issue.getCustomFieldValue(reporter).name
issue.setReporterId(cf)

So simply solution! Thanks!!!

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

459 views 3 17
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you