Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Groovy Script check if assignee belong to group based on field answer

baosjk June 11, 2014

I have never used groovy script before so I'm really trying to understand it.

The situation is this:

There is the 'assignee to me' where I or anyone else can assignee to issue to themselfs.

What I'm trying to do is check the value of a custom field and if for example this field value is '10709' only members from the

'jira-test1-group' can assignee the issue to themselfs.

So after read some topics on this forum I believe the solution is on the groovy script. I'm right? I run this script and I got some errors.

javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issue for class: Script3

Can someone help me?

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
 
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()
 
CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "customfield_11501"}

def groupManager = ComponentAccessor.getGroupManager()
 
cfwt = issue.getCustomFieldValue(sccField)
 
if (cfwt == "10709"){ 
  
!((groupManager.isUserInGroup(issue.assignee?.name, 'jira-test1-group')))

}


2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2014

I suspect the problem is you are running this from admin console, where there is no issue in the context? Look at other examples to see how you can get an issue instance, or run it as a workflow function.

0 votes
Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 12, 2014

Try to add the following in the beginning of your script

import com.atlassian.jira.issue.Issue;

Hope that helps

TAGS
AUG Leaders

Atlassian Community Events