Plugin to create / update issues (Jira 7.1.8)

How can i create or update issues within a plugin? 

i can get all the issues with JQL and i want to update (or also create a new one) some of them, if the data i get from outside are not the same


1 answer

1 accepted

1 vote
Accepted answer

What kind of plug-in are you developing - Server or Cloud?

For Server you can use the Java APIs - take a look at IssueService. For Cloud you need to use the REST APIs. Let me know if you have a more concrete question.

i am developing for server

i had a look on IssueService and build this code. Am i on the right track?

IssueInputParameters parameters =  issueService.newIssueInputParameters();
parameters.setDescription("description");	//example
// item.getId() gets the issueId that have to be updated
UpdateValidationResult updateResult = issueService.validateUpdate(currUser, new Long(item.getId()), parameters);	//updates the issue

Yes, that's the way to do it, you just need to add the actual update invocation:

issueService.update(currUser, updateResult);

The pattern for creating an issue is the same - validateCreate() then create().

thanks a lot, updating is working smile

but i have some problem creating a new issue.. I add the IssueInputParameters like that, but it do not work:

private IssueInputParameters addParameters(IssueInputParameters par, Long projId) {
		return par;

have i to do anything else?

You need to call issueService.validateCreate() and then create(). What do you mean by "it does not work"? Is there an error thrown?

it works now, i think the problem was i only set the project-id and the description.. after i set all the required fields (summary, issuetype, reporter-id) it created a new issue smile


Another question: 
how can i set an ApplicationUser? now i set him as the logged-in one.. but later it should be always the same user with admin-permissions..

can i do it that way:

ApplicationUser currUser = userManager.getUserByName("admin");

Yes, you could do that, but you need to make sure that user has sufficient permissions to create issues. Also hardcoding users in your code has its own drawbacks - the user name may change, the user may get deleted, etc. If you really want to have a service user which will be used to create issues, maybe you should think about making that user selectable via a configuration UI so that at least it's not hardcoded in you plug-in code.

ok thanks a lot for your detailed answer, i will regard this.

now i had an other prolbem: i want to set the Components and the Status of the IssueInputParameters. i do it like that:

IssueInputParameters par;
getComponents(Object item) {
	// gets all the components from Jira, parse them with a List from the item-object, if there is a match save it to a Long-Array and after return the Long-Array 
getStatusId(Object item) {
	// gets all statuses from Jira and parse them with the one from the item-object, returns a String with the ID of the Status from Jira

The methods "getComponents" and "getStatusId" return a valid Long-Array and String, i proof that... the components exist in Jira, i could select them directly from JIRA ..

Maybe you have an idea what i do wrong

thanks for your great help smile

Hm, I don't think you can set the status ID like that - you'll need to transition the issue to that status after the issue is created.

You didn't mention what goes wrong - does validateCreate return errors or just the issue is created with no components?

components work now. First I create an issue without components and after i update that issue with the components.. that works fine now

i try the same with the status but it do not change the status (the status i want to set is valid: f.e.: i want to set it from "Open" to "In Progress"). there are no errors about that


Another thing.. now my plugin is a Scheduler that runs every X minutes.. updating issues work but if it should create a new issue, i get this error:

Errors: {pid=Anonymous users do not have permission to create issues in this project. Please try logging in first.}

so i think i have to tell my plugin to login a user that can create issues.. but how can i do that? how can i login a user within a plugin?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Jira

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,081 views 0 8
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