On issue creation I want to automatically assign the reporter with a specific person (i.e. not the person creating the issue), i,m trying to use script runner post function in create transition of workflow. I had a script that add particular user as watcher can any one modified the script to particular user assign to reporter.
Here the script below
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
def userName = "user name"
def userManager = ComponentAccessor.getUserManager()
MutableIssue issue = issue as MutableIssue
def user = userManager.getUserByName(userName)
def watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(user, issue)
Thanks in advance
Siva
Hi @siva For this simple task , scripted post function is not required.
simply use post function update issue fields . Select Reporter >> Add username
For script runner :-
issue.reporterId = "xyz"
Thanks
Hi @Vikrant Yadav thanks for the reply,
I tried update issue field in post function but it didn't see the reporter as an option in drop down.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @siva Then simply use script post function add below script :- It should work.
You are right reporter is not avialable in Update issue field.
issue.reporterId = "xyz"
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.
Hi @siva I have tested the same on my side. It's working fine. Are you using it on Create Issue transiton ?
If yes, then move it below Create Issue event.
Check project permissions as well
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav Yes, it's using on create transition and i move it below create issue event still no response in reporter field. Please let know where i did wrong.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @siva Above script works for other transitions. For Create Issue use below script :-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Level
import org.apache.log4j.Logger
def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)
def user = ComponentAccessor.getUserManager().getUserByName("vikrant-yadav2")
issue.setReporter(user)
Hope it works for you.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Vikrant Yadav ,
issue.reporterId = "xyz"
The above script works for me and it used in script runner post function create sub task. I used that script in create sub task in script runner.
Thank you very much for your help.
Regards,
Siva
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@siva Cool! Glad to hear it works for you. :)
Kindly mark the solution as Accepted. It helps other users having same problem.
Thanks
V.Y
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Siva,
What about something like:
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.util.UserManager
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue issue = issueManager.getIssueObject("DEMO-1");
UserManager userManager = ComponentAccessor.getUserManager()
def issueReporter = userManager.getUserByName("charlie")
issue.setReporter(issueReporter)
issueManager.updateIssue(issueReporter, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Please let us know how it goes!
Regards,
Hyrum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hyrum Steffensen {Appfire} thanks for the response,
I tried your script and it throws the following error log
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2021-06-21 23:21:46,764 ERROR [workflow.AbstractScriptWorkflowFunction]: ************************************************************************************* 2021-06-21 23:21:46,764 ERROR [workflow.AbstractScriptWorkflowFunction]: Script function failed on issue: NMS-77233, actionId: 1, file: null java.lang.NullPointerException: Cannot invoke method setReporter() on null object at Script495.run(Script495.groovy:11)
Please let me know where to change script
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Siva,
I believe the problem is this line:
MutableIssue issue = issueManager.getIssueObject("DEMO-1");
You must specify an issue key that exists on your system instead of "DEMO-1". This may also work:
MutableIssue issue = issue as MutableIssue
Please note that you must also change this line to accept a username of a user that exists on your system.
def issueReporter = userManager.getUserByName("charlie")
Regards,
Hyrum
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.