Assignee Script working in console but its not working on postfunction

kalyan kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2019

Hi

The below Script Its working in console to change assignee its updating in history perfectly 

but the assignee to me place its not showing the assignee name   so please check it and let me know if any updates 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import static java.util.Calendar.*
import org.apache.log4j.Category

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
def mySourceIssue = issueManager.getIssueObject("JP-1")

mySourceIssue.getSummary()

mySourceIssue.getProjectObject().getName()

mySourceIssue.getIssueType().getName()

ApplicationUser user =mySourceIssue.getAssignee()
log.error("user name "+ user.getName())
log.error("user name "+ user.getDisplayName())
// update user
String userName = "janakiram";
def userManager = ComponentAccessor.getUserManager()
ApplicationUser modifiedUser = userManager.getUserByName(userName);

MutableIssue mutableIssue = issueManager.getIssueByCurrentKey("JP-1")
mutableIssue.setAssignee(modifiedUser);
issueManager.updateIssue(loggedInUser,mutableIssue,EventDispatchOption.ISSUE_UPDATED,true)

1 answer

0 votes
Marcos Sanchez
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.
May 27, 2019

Hi!

As I can understand, you want to use the same script that you used in console, but in a workflow postfunction.

This code should work:

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

def issueManager = ComponentAccessor.issueManager
def userManager = ComponentAccessor.userManager

def loggedUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def user = userManager.getUserByName("") //there goes the username

issue.setAssignee(user)
issueManager.updateIssue(loggedUser, issue, EventDispatchOption.ISSUE_UPDATED, true)

It's the same as yours, but without setting the issue variable and without getting current Assignee.

You have to put it on a Script Post Function -> Custom Script Post Function.

Hope it helps,
Marcos

Suggest an answer

Log in or Sign up to answer