I need help
I need to create a script that verifies that the reporter of the issue is part of a particular group, if yes, all people who participate in this group must be inserted in the request participants.
This is my second contact with scriptrunner / groovy (I can not write this script alone)
JIRA 7.1.7
Request participants (customfield_11200)
Script Runner 4.3.18
Thank you all for your help.
Community moderators have prevented the ability to post new answers.
You can use the following script in a scripted post-function as the last one on the create transition or as a listener on the issue created event which will run when the issue is created.
You'll need to replace the group name with your one.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def groupManager = ComponentAccessor.getGroupManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def issueService = ComponentAccessor.getIssueService() def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issue = issue as Issue // replace this with your group def groupName = "special-group" if (groupManager.isUserInGroup(issue.reporter, groupName)) { def users = groupManager.getUsersInGroup(groupName) def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001") users.each { user -> def issueInputParameters = issueService.newIssueInputParameters() issueInputParameters.with { addCustomFieldValue(requestParticipantsField.idAsLong, users*.id*.toString().toArray()) } def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters) if (updateValidationResult.isValid()) { issueService.update(currentUser, updateValidationResult) } else { log.warn updateValidationResult.errorCollection.errors } } }
Thank you @Adam Markham [Adaptavist],
But it did not work.
I inserted this script in the last post function of the creation transition.
I changed the 'special-group' information to the group I want to check
The issue is open, but the request participants field is empty.
Did I do something wrong?
One thing I noticed in the script when I put it on the console is that line 9 was highlighted:
Script Console - Service Support Tool - Google Chrome.jpg
But when I put in the post-funtion does not
(Is there any log that I can send to try to better understand the error?)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That line you get the error on can you remove it please. The issue should already be in the binding so you don't have to declare it there.
Try and see if it works after that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As for it not working. Do you see anything in the atlassian-jira.log after creating the issue? If it didn't update the request participants then I'd expect to see an error in the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Adam Markham [Adaptavist]
Even removing the line that presented the error, the script still does not work.
This is the error message that appears in the log.
Time (on server): Mon Mar 20 2017 07:36:02 GMT-0300 (Hora oficial do Brasil) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2017-03-20 07:36:02,592 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-03-20 07:36:02,592 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: FLEX-4495, actionId: 1, file: <inline script> groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.addCustomFieldValue() is applicable for argument types: (java.lang.Long, java.util.ArrayList) values: [11200, [dante.labate(dante.labate), fidelity(fidelity), ricardo.maganhati(ricardo.maganhati)]] at Script39$_run_closure1$_closure2.doCall(Script39.groovy:22) at Script39$_run_closure1.doCall(Script39.groovy:21) at Script39.run(Script39.groovy:19)
Apparently it lists the people who are in the group, but does not appear in the request participants.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've updated that line of the script. It should work now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Adam Markham [Adaptavist]
Not yet
Time (on server): Mon Mar 20 2017 09:34:55 GMT-0300 (Hora oficial do Brasil) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2017-03-20 09:34:55,408 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-03-20 09:34:55,408 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: FLEX-4497, actionId: 1, file: <inline script> groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.addCustomFieldValue() is applicable for argument types: (java.lang.Long, [Ljava.lang.Object;) values: [11200, [dante.labate(dante.labate), fidelity(fidelity), ricardo.maganhati(ricardo.maganhati)]] at Script54$_run_closure1$_closure2.doCall(Script54.groovy:22) at Script54$_run_closure1.doCall(Script54.groovy:21) at Script54.run(Script54.groovy:19)
The execution of the script is soon after the creation of the issue in the post function
Is correct?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Adam Markham [Adaptavist]
Any idea?
Users are not added in the request participants field
Tanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's actually a better example here: https://confluence.atlassian.com/jirakb/how-to-automatically-add-request-participants-when-creating-an-issue-777026955.html
I've updated my version of the script so that it should now work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please ensure the custom field id we are using matches up with the id you have for your request participants field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Adam Markham [Adaptavist]
Error occurred
Time (on server): Wed Mar 22 2017 08:34:10 GMT-0300 (Hora oficial do Brasil) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2017-03-22 08:34:10,066 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2017-03-22 08:34:10,066 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: FLEX-4508, actionId: 1, file: <inline script> groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.addCustomFieldValue() is applicable for argument types: (java.lang.Long, [Ljava.lang.Object;) values: [10001, [12300, 10801, 12304]] at Script7$_run_closure1$_closure2.doCall(Script7.groovy:23) at Script7$_run_closure1.doCall(Script7.groovy:22) at Script7.run(Script7.groovy:20)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Adam Markham [Adaptavist]
I checked and the ID of the request participants is 11200.
I only change these two information:
I put the name of the group I want to check
I put the correct value in customfield_xxxx
The call is created, but no one in the field requests participants.
I was testing so far with the post-function script.
Test putting scritp on Listerns with event creation issue
The error is different in log.
Time (on server): Thu Mar 23 2017 09:44:17 GMT-0300 (Hora oficial do Brasil) The following log information was produced by this execution. Use statements like:log.info("...") to record logging information. 2017-03-23 09:44:17,397 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2017-03-23 09:44:17,398 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> java.lang.NullPointerException: Cannot get property 'reporter' on null object at Script142.run(Script142.groovy:15)
This is the script that is running.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def groupManager = ComponentAccessor.getGroupManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def issueService = ComponentAccessor.getIssueService() def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def issue issue = issue as Issue // replace this with your group def groupName = "Clients" if (groupManager.isUserInGroup(issue.reporter, groupName)) { def users = groupManager.getUsersInGroup(groupName) def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_11200") users.each { user -> def issueInputParameters = issueService.newIssueInputParameters() issueInputParameters.with { addCustomFieldValue(requestParticipantsField.idAsLong, users*.id*.toString().toArray()) } def updateValidationResult = issueService.validateUpdate(currentUser, issue.id, issueInputParameters) if (updateValidationResult.isValid()) { issueService.update(currentUser, updateValidationResult) } else { log.warn updateValidationResult.errorCollection.errors } } }
I do not know what to do anymore
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.