Hi folks,
i just tried to get a scripted validator up&running, but it´s not working as expected:
import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(issue.reporter?.name, 'Technical User') || ( issue.issueTypeObject.name != ('Incident')|| issue.issueTypeObject.name != ('Service Call')|| issue.issueTypeObject.name != ('Change Request')|| issue.issueTypeObject.name != ('Problem')|| issue.issueTypeObject.name != ('Workorder') )
The idea is to limit the creation of some specific issue types to specific user group only, so the reporter has to be part of the group "Technical User" or the to be created issue type is not in "Incident, Service Call, Change Request, Problem, Workorder".
Any ideas what i´m doing wrong? Unfortunately my programming skills are very limited...
Thanks & regards,
Hans-Hermann
Try:
import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(issue.reporter?.name, 'Technical User') || ! (issue.issueTypeObject.name in ['Incident', 'Service Call', 'etc'])
if it's still not working tell us how it's not working.
Beware of the formatting... you can't begin a newline with || if the previous line is a valid groovy statement. There are perils to not using semi-colons.
@Jamie Echlin [Adaptavist]
Hi Jamie, I'm trying to do the opposite of the solution you showed above but I'm getting the "Use one of the other isUserInGroup
methods that takes a concrete user object instead. Since v6.4.8." error. We are running JIRA 7.0. Any thoughts?
import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(issue.reporter?.name, 'jira-administrators') || (issue.getIssueType() in ['Goal'])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just from the wording of the error, it sounds like they want you to use "issue.reporter" instead of "issue.reporter?.name".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yep, JIRA 7 has some changes to the API. Thanks @Jeremy Gaudet
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I would like to have on my custom transition script validator that reporter has to be part of the project role "Developers".
Thanks!
BR
P.S. JIRA 7.6
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You may know this, but I'm calling it out because it's not clear. You need to do something like:
import com.opensymphony.workflow.InvalidInputException import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() if (!(groupManager.isUserInGroup(issue.reporter?.name, 'Technical User') || (issue.issueTypeObject.name != 'Incident' &&issue.issueTypeObject.name != 'Service Call' && issue.issueTypeObject.name != 'Change Request' && issue.issueTypeObject.name != 'Problem' &&issue.issueTypeObject.name != 'Workorder'))) { invalidInputException = new InvalidInputException("Only users in the \"Technical User\" group can open issues of type \"" + issue.getIssueType() +"\"") }
I have the same validator on "Create Issue", except it's based on the Developers role, to give you a complete working example:
import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.security.roles.ProjectRoleManager import com.atlassian.jira.security.roles.ProjectRoleActors import com.atlassian.jira.security.roles.ProjectRole import com.opensymphony.workflow.InvalidInputException import org.apache.log4j.Category def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction"); ComponentManager componentManager = ComponentManager.getInstance(); ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager; ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser(); ProjectRole devsRole = projectRoleManager.getProjectRole("Developers"); ProjectRoleActors devs = projectRoleManager.getProjectRoleActors(devsRole, issue.getProjectObject()); Boolean isDev = devs.contains(currentUser); String issueType = issue.getIssueTypeObject().getName(); if (!isDev) { if (issueType != "Bug" && issueType != "Improvement") { invalidInputException = new InvalidInputException("You are not a member of this project's \"Developers\" role; the only issue types available to non-developers are \"Bug\" and \"Improvement\"."); } }
(I removed some other exception blocks to keep it simple, but it should still work as-is).
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 throw a new InvalidInputException if you're using a custom validator... from the way the code was written by the OP I assume it was a "simple scripted validator". In that case you just return true/false, and set the message in the UI. It's slightly simpler.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Interesting. Is his return method correct in that case? It's a free-form expression evaluation without a "return", so it still seems odd, but I've never used a "simple scripted validator".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The return statement is implicit for the last line of a block. So it's correct not to use that, but there were other errors. I prefer not to use "return" if it's obvious.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think your block of OR statements on the issue type is a problem - it's always going to be true. If an issuetype is an Incident, then it is not any of the others, so all the other clauses become true. Try AND instead (if issuetype is not A and it's not B and it's not C then...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, Nic is right. I updated my answer below to take account of that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, typing at the same time :-)
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.