Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How Do I Assign an Issue based on assignee not in membersOf?

Deleted user July 23, 2018

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!

1 answer

1 accepted

1 vote
Answer accepted
Deleted user July 24, 2018

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 ''

Deleted user July 24, 2018

Thanks Cristian!! I'll give it a shot. :)

Deleted user July 24, 2018

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....

Deleted user July 24, 2018

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)
Deleted user July 24, 2018

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.

Deleted user July 24, 2018

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

Deleted user July 25, 2018

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

Deleted user July 27, 2018

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

 

Deleted user July 27, 2018

Edited

Chris Annal
Contributor
July 30, 2018

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. :(

Deleted user July 31, 2018

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?

Deleted user July 31, 2018

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

  • Reporter is in a particular group

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!! :)

 

Deleted user July 31, 2018

Fantastic news! glad to help

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events