Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi everyone,
i need to set the reporter on create issue based on a custom field which is read over nfeed. the custom field E-Mail is the username of the user in jira itself.
we have the addon script runner so we can user a groovy script.
can somebody help me please. i tried several scripts here but it does not work.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("")
def newreporter = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E-Mail")
def newreportervalue = issue.getCustomFieldValue(newreporter)
issue.setReporter(newreportervalue)
the problem should be related to getCustomFIeldValue that should return a generic value and not a ApplicationUser.
Please, try this code :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
Issue issue = getUnderlyingIssue();
MutableIssue mIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey());
CustomField newreporter = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E-Mail");
String newreportervalue = issue.getCustomFieldValue(newreporter)!=null?issue.getCustomFieldValue(newreporter).toString():null;
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(newreportervalue);
if(user!=null){
mIssue.setReporter(user);
}
Hope this helps,
Ciao,
Fabio
now this error occurs:
Time (on server): Wed Feb 06 2019 13:09:45 GMT+0100 (Central European Standard Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-02-06 13:09:45,054 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-02-06 13:09:45,054 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INUBIT-20, actionId: 1, file: <inline script> java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object at Script60.run(Script60.groovy:8)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure hthat CustomFIeld name is correct?
try this :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.fields.CustomField;
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("");
CustomField newreporter = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E-Mail");
String newreportervalue = issue.getCustomFieldValue(newreporter)!=null?issue.getCustomFieldValue(newreporter).toString():null;
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(newreportervalue);
if(user!=null){
issue.setReporter(user);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes i'm sure :->
2019-02-06 14:21:48,390 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-02-06 14:21:48,390 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INUBIT-22, actionId: 1, file: <inline script> java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object at Script71.run(Script71.groovy:10)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
got it! issue object is null.
Try this :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
Issue issue = getUnderlyingIssue();
MutableIssue mIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey());
CustomField newreporter = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E-Mail");
String newreportervalue = issue.getCustomFieldValue(newreporter)!=null?issue.getCustomFieldValue(newreporter).toString():null;
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(newreportervalue);
if(user!=null){
mIssue.setReporter(user);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2019-02-06 14:33:01,573 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-02-06 14:33:01,573 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: INUBIT-23, actionId: 1, file: <inline script> groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getUnderlyingIssue() is applicable for argument types: () values: [] at Script76.run(Script76.groovy:7)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Issue issue = getUnderlyingIssue();
this method is provided by ScriptRunner. Are u using this plugin or is it something custom? In the second option you need to retrieve the issue key based on the context.
Ciao,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes i'm sure, scriptrunner is installed and up2date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
strange, it should work.
Try using directly issue (delete line "Issue issue = getUnderlyingIssue();" from previous script.
Let me know,
Ciao,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
there is no error now but the reporter is not set / changed :-<
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to persist the change :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue mIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey());
CustomField newreporter = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("E-Mail");
String newreportervalue = issue.getCustomFieldValue(newreporter)!=null?issue.getCustomFieldValue(newreporter).toString():null;
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(newreportervalue);
if(user!=null){
mIssue.setReporter(user);
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), mIssue, EventDispatchOption.DO_NOT_DISPATCH, false);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
and again no errors but the reporter remains unchanged :-<
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please debug your code in order to figure out if user has a value
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.