I am working on a post-function script to assign an issue to a default jira user named "cmdefault" if the issue isn't currently assigned to a member of the cm group. From what I've read, I believe I would start with something like this...
assignee not in membersOf("config-mgmt")
and if that condition was "True", then change the assignee to "cmdefault". I've having a bit of a problem because it's not clear to me how the entire post-function script (Scriptrunner) is constructed.
if assignee not in membersOf("config-mgmt")
issue.setAssigneeId("config-mgmt")
Something tells me it can't possibly be this easy, but I'm hoping my example lines above at least catch the drift of what I'm trying to do as a post function. Does anyone have a suggestion that might help me with this post-function script?
Thanks a lot!
Hi @[deleted],
As you have guessed, it is not that simple to use JQL in a post function. Anyway, you don't even need to use JQL, you can use a very simple boolean expression with groupManager:
import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccesor.getGroupManager()
if (groupManager.isUserInGroup(issue.assignee; "nameOfGroup")) {
issue.setAssigneeId("userId")
}
You need to use the exact string (including Caps). Also, I don't know which user you want to set as assignee so, I left this as "userId", but make sure that the id is between "" or ''
Thanks Cristian!! I'll give it a shot. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, this didn't work as a scripted post function in our version of JIRA (6.3.10). It didn't error, but it didn't update the assignee to the desired user, either. I'll keep playing with it, since this looks like it should work. I just haven't figured out why it doesn't....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where is this ubicated? Remember that the user chosen MUST have the assignable user permission.
Try including this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def groupManager = ComponentAccesor.getGroupManager()
def issueManager = ComponenteAccesor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
if (groupManager.isUserInGroup(issue.assignee; "nameOfGroup")) {
issue.setAssigneeId("userId")
}
issueManager.updateIssue(currentUser, issue, 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.
Still no joy. I know that I've heard elsewhere that using the "old" free version of Scriptrunner, especially the Custom script post-function (Inline script) may require slight modifications to scripts that would otherwise work in newer versions of Scriptrunner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have checked the jira 6 API and the code looks fine. Check if the user have assignable user permission.
Also, to see if there is some problem with the code go to the console and do this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def groupManager = ComponentAccesor.getGroupManager()
def issueManager = ComponenteAccesor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = issueManager.GetIssueObject(XX-000)
log.warn currentUser
log.warn issue.assignee
log.warn groupManager.getGroup("nameofgroup").name
log.warn groupManager.isUserInGroup(issue.assignee; "nameOgGroup")
If it doesn't work I'll try to install an old version of jira tomorrow in a virtual machine and try it myself
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for all your help. I really appreciate it. When I try the above in console, I get this error:
Error
startup failed: Script32.groovy: 13: Expression list of the form (a; b; c) is not supported in this context. at line: 13 column: 37. File: Script32.groovy @ line 13, column 37. log.warn groupManager.isUserInGroup(issue.assignee; "nameOgGroup") ^ 1 error
I also tried it in the console using an actual issue number and the actual group name ("config-mgmt"), but got the same error...
Error
startup failed: Script33.groovy: 13: Expression list of the form (a; b; c) is not supported in this context. at line: 13 column: 37. File: Script33.groovy @ line 13, column 37. log.warn groupManager.isUserInGroup(issue.assignee; "config-mgmt") ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I couldn't try it in an actual version of Jira 6, anyway, it looks like it doesn't like isUserInGroup
Try this:
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def groupManager = ComponentAccesor.getGroupManager()
def issueManager = ComponenteAccesor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def group = groupManager.getGroup("nameOfGroup") as Group
if (groupManager.isUserInGroup(issue.getAssignee(); group)) {
issue.setAssigneeId("userId")
}
issueManager.updateIssue(currentUser, issue, 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.
Edited
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cristian. I'm not sure why, but I still don't get the desired result of having the issue assigned to a default user if the assignee isn't in a certain group. I try variations of your suggestions, besides just using the exact suggestion....but the test issues I've tried to have the assignee updated as a post function with just remain assigned to the same (not in the desired group) assignee.
For example, I've tried putting "!" as part of the "if" condition...
if !(groupManager.isUserInGroup(issue.getAssignee(); group))
I've also tried a suggestion that uses a question mark...
if !(groupManager.isUserInGroup(issue.assignee?.name, "nameOfGroup"))
so far, using an inline script on the post function doesn't seem to work for me. :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I ve just seen an obvious mistake in the code I sent. Change ; for , although it look you have already done it. What does the console say now?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cristian,
I just couldn't get the script to work, but I did find a suitable workaround in my case. Here's what I did.
I used the built-in Scriptrunner Simple Scripted Validator for
but modified it to "assignee" as follows:
import com.atlassian.jira.component.ComponentAccessor def groupManager = ComponentAccessor.getGroupManager() groupManager.isUserInGroup(issue.assignee?.name, 'config-mgmt')
The dialog for that script includes an entry for an "Error Message" to pop up when that validation fails, and I put "Assignee must be a member of the CM Group. Members can be found here: <I put a hyperlink to the list of current members here>.
I selected "Assignee" as the Form field that the error message will appear against, and this works perfectly well for our purposes.
I can't thank you enough for your attention to this. It helped me find something that finally works for our usage!! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fantastic news! glad to help
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.