import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
userManager = (UserManager) ComponentAccessor.getUserManager()
MutableIssue issue = issue
IssueManager issueManager = ComponentAccessor.getIssueManager()
def groupManager = ComponentAccessor.getGroupManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField mycustomfield = customFieldManager.getCustomFieldObjectByName("CF_Priority")
String mycustomfieldValue = (String) issue.getCustomFieldValue(mycustomfield)
if(mycustomfieldValue != null)
{
if(mycustomfieldValue.equals("1")){
isUserMemberOfRole('JIRA-user-group1')
}
if(mycustomfieldValue.equals("2")){
isUserMemberOfRole('JIRA-User-group2')
}
if(mycustomfieldValue.equals("Major")){
isUserMemberOfRole('JIRA-User-group3')
}
}
Please suggest what is wrong in the script. Its not working as expected.
Hello,
You are not updating the custom field value anywhere on the script as I can see. Did you not paste the full code on purpose? If not that's why it's not working. You should update the custom field like this:
issue.setCustomFieldValue(customfield,
"testing"
);
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH,
false
)
Regards.
Hello Elifican,
Thank you for the reply.
getting error while running my script.
2019-04-03 09:26:06,088 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-04-03 09:26:06,094 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script131.groovy: 13: unable to resolve class UserManager @ line 13, column 15. userManager = (UserManager) ComponentAccessor.getUserManager() ^ 1 error
Can you please help me to solve this error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Could you try like this:
import com.atlassian.jira.user.util.UserManager;
UserManager userManager = ComponentAccessor.getUserManager()
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Elifcan_Cakmak , I have the same scenario , when assignee is changed a custom field value should be changed/reset to null . I tried above solution and did not work using "issue assigned" custom listener . Can you please post a working code here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.