It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to Assign Issues using Java

  • I have set up a JIRA server on a local machine and have created A software project and have uploaded issues using excel.
  • The motive is to modify few fields using Java like: STATUS, getIssueID based on issue title and upload docs and also to modify assignee and Labels.
  • Struck at modifying assignee and Labels.
  • Please find the gist of pom.xml

2 answers

1 vote
Rambabu Patina Community Leader Oct 10, 2018

Hi @Pavan Kumar Bachu, Please have a look at the similar question at https://community.developer.atlassian.com/t/componentaccessor-not-initialised/1143.

Hope this helps you. Thanks. 

@Rambabu Patina  I  have tried that solution but it's throwing null pointer when setting assignee?

IssueManager mockIssueManager = mock(IssueManager.class);
final MockComponentWorker componentAccessorWorker = new MockComponentWorker();
componentAccessorWorker.addMock(IssueManager.class,mockIssueManager);
ComponentAccessor.initialiseWorker(componentAccessorWorker);
MutableIssue io = ComponentAccessor.getIssueManager().getIssueObject(issueID);
io.setAssignee(" ");

 

 

 

Rambabu Patina Community Leader Oct 10, 2018

@Pavan Kumar Bachu Here what's the user id you are providing in the method

setAssignee(<Provide valid user id>) 

I am passing a regular string, is there a better way to get the user id?

Rambabu Patina Community Leader Oct 11, 2018

Try this way:

setAssignee(ApplicationUser assignee) // For this method you have to pass the type ApplicationUser

setAssigneeId(String assigneeId) // For this method you can provide user id.

How do we get the Application User instance ?

Rambabu Patina Community Leader Oct 11, 2018

@Pavan Kumar Bachu

You already have the ComponentAccessor reference, so

If you want to get the current logged in user try

ApplicationUser currentUser  = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

To get other users try:

ApplicationUser currentUser  = ComponentAccessor.getUserManager().getUserByKey(String userKey);

or 

ApplicationUser currentUser  = ComponentAccessor.getUserManager().getUserByName(String userName);

Hope this helps you.

Tried Code 
IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue io = issueManager.getIssueObject(issueID);
io.setAssigneeId("XXXX");

 

Got exception 

This is not expected to occur on a production system.
Developers that encounter this message within a unit test
should use n MockitoMocksInContainer rule to initialize mockito and ComponentAccessor.
For more detailed explanation read the documentation
for MockComponentWorker in the jira-tests artifact for more information
about what causes this error and how to address it.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Introducing new features for Jira Software Cloud's roadmap

Hi Atlassian community, A few months ago, we offered a sneak peak of the new hierarchy view on the roadmap. Thank you for all the feedback (and excitement) and for helping us shape the direction of...

25,420 views 118 90
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