Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,949
Community Members
 
Community Events
165
Community Groups

Unable to set approver in JIRA service desk

Hi,

I am using JIRA service desk 3.4.3 with JIRA 7.3 and script runner 5.0.14.

I want to set approver automatically on create issue transition. Here is my code. This returns error

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
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.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()

IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField CF = customFieldManager.getCustomFieldObjectByName("Approvers");
def user = userManager.getUserByName("admin")
issue.setCustomFieldValue(CF, user);


I am getting error on creating issues and error logs as follows, I have couple other scriptrunner post functions which work fine with the same version of plugin 

 

2017-12-19 16:27:41,590 http-nio-8080-exec-9 ERROR a570296 987x199807x1 12p4hbv 10.195.144.12,10.192.128.167 /servicedesk/customer/portal/122/create/395 [c.a.j.bc.issue.DefaultIssueService] Error creating issue: com.atlassian.jira.exception.CreateException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:588) at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:494) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.createIssue(RequestCachingIssueManager.java:192) at com.atlassian.jira.bc.issue.DefaultIssueService.create(DefaultIssueService.java:238) at com.atlassian.jira.bc.issue.DefaultIssueService.create(DefaultIssueService.java:207) ... 2 filtered at java.lang.reflect.Method.invoke(Method.java:498) at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26) at com.sun.proxy.$Proxy110.create(Unknown Source) ... 2 filtered at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56) at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at

1 answer

Try calling this at the end of your script:

issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

You'll also need to 

import com.atlassian.jira.event.type.EventDispatchOption

 

I do something very similar: Here is my code that I got to work on Jira Server 7.5.0

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ProjectManager projectManager = ComponentAccessor.getProjectManager()

def customFieldProject = customFieldManager.getCustomFieldObjectByName("Project Selection")
def projectName = issue.getCustomFieldValue(customFieldProject).toString().substring(9)
projectLead = projectManager.getProjectObjByKey(projectName).getProjectLead()

log.debug(projectName.toString())
log.debug(projectLead.toString())

CustomField customFieldApprovers = customFieldManager.getCustomFieldObjectByName( "Approvers" );

issue.setCustomFieldValue(customFieldApprovers, [projectLead])

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueManager issueManager=ComponentAccessor.getIssueManager();
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

log.debug(issue.getCustomFieldValue(customFieldApprovers).toString())
 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

330 views 2 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you