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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 9 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

34 views 0 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you