Change project with IssueService

Ragnar Skulason March 19, 2013

Can you change issue's project with IssueService.

i.e.

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

issueInputParameters.setProjectId(anotherProjectID);

IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(authenticationContext.getLoggedInUser(), issueId, issueInputParameters);
//updateValidationResult.isValid() returns true


IssueService.IssueResult update = issueService.update(authenticationContext.getLoggedInUser(), updateValidationResult);
//update.isValid() returns true

But the issue still belongs to the original project.

If I add other input parameters, i.e. description, they do get changed so the update works, but just not for the project.

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Ragnar Skulason March 19, 2013

As far as I can see, this can not be done with IssueService.

This can be done easily with IssueManager instead.

MutableIssue issueObject = issueManager.getIssueObject( issueId );
        Project projectObject = projectManager.getProjectObj(projectId);
        issueObject.setProjectObject(projectObject);
        issueObject.setKey(projectObject.getKey() + "-" + projectManager.getNextId(projectObject));
        issueObject.store();

Edit:

* This is depricated and will stop functioning sometime, I still havn't found the proper way to move issue. I'll update this answer when I do.

* issueManager.updateIssue changed to issueObject.store();

RambanamP
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.
March 20, 2013

is your tring to move the issue to some other project or just changing project?

if you are moving issue then you can't do this through api

Like Kuharev Artem likes this
Ragnar Skulason March 20, 2013

Is there a difference betwean move to another project and change a project?

Like Kuharev Artem likes this
RambanamP
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.
March 20, 2013

yes, if you change the project to issue it will change just project name but does't change issuekey of new project,

if you move the issue it will change both.

check the following post

https://answers.atlassian.com/questions/150179/how-to-move-an-issue-programatically-to-a-different-project?page=1#150284

Ragnar Skulason March 20, 2013

Thanks Rambanam Prasad,

This actually works. Changes the project and sets a new project key.

MutableIssue issueObject = issueManager.getIssueObject(issueId);
Project projectObject = projectManager.getProjectObj(projectId);
issueObject.setProjectObject(projectObject);
issueObject.setKey(projectObject.getKey() + "-" + projectManager.getNextId(projectObject));
issueObject.store();

BUT....

MutableIssue's issueObject.store() is marked obsolete, so it's not very vise to use it in a new plugin.

I'm going to try to find another way....

sohil chhabriya March 21, 2013

your code has some probjem projectManager object not created

Ragnar Skulason March 26, 2013

Yes,

I inject IssueManager issueManager and ProjectManager projectManager in the cosntructor

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 19, 2013

I really don't think you can just "change the project". You need to use "move" to move the issue from one project to another. The validate call you've found will probably enable you to check if some of the move process is ok, but I suspect there's a lot more to do than that.

David Lemon April 28, 2013

well There is no move() in the jira api for moving the issue.

only we have a UI control which does that..

do we have some programatical solution?

0 votes
Henning Tietgens
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.
March 20, 2013

You can set the following parameter to skip these checks:

issueInputParam.setRetainExistingValuesWhenParameterNotProvided(true,true);
issueInputParam.setApplyDefaultValuesWhenParameterNotProvided(false);
issueInputParam.setSkipScreenCheck(true);

But beside that, I don't think it's possible to move the Issue through simply changing the project.

Henning

0 votes
Ragnar Skulason March 19, 2013

As far as I can see, this can not be done with IssueService.

This can be done easily with IssueManager instead.

MutableIssue issueObject = issueManager.getIssueObject( issueId );
        Project projectObject = projectManager.getProjectObj(projectId);
        issueObject.setProjectObject(projectObject);
        issueObject.setKey(projectObject.getKey() + "-" + projectManager.getNextId(projectObject));
        issueManager.updateIssue(authenticationContext.getLoggedInUser(), issueObject, EventDispatchOption.ISSUE_UPDATED, false);

0 votes
Ragnar Skulason March 19, 2013

from: com.atlassian.jira.bc.issueInterface IssueService

validateUpdate

This method will validate that the provided parameters are valid for the fields that are specified by the configured edit screen for the issues project/issue type. Any fields that are not included on the edit screen will not be validated or populated.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events