Forums

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

i am trying to change the custom field value based on assignee belongs to user group

kumar_ankush_in_bosch_com April 2, 2019

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.

 

1 answer

1 vote
Elifcan Cakmak
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.
April 3, 2019

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.

kumar_ankush_in_bosch_com April 3, 2019

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.

Elifcan Cakmak
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.
April 3, 2019

Hi,

Could you try like this:

import com.atlassian.jira.user.util.UserManager;

UserManager userManager = ComponentAccessor.getUserManager()

Regards. 

Deleted user May 1, 2020

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. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events