How to Move issue only specified status?(Programatically or not)

Hi,

A customer wants to be able to move issue (but everyone in the developer user is allowed) from every status to only a specified status("open" status for exp.) ?

How can i restrict to status(programatically or not)

I tried with the script listener. Action is Issue Moved.

Here is my code :

import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.jira.workflow.TransitionOptions;
import com.atlassian.jira.workflow.WorkflowSchemeManager;

log.warn("issue moved");
log.warn("status : " + event.getIssue().getStatus());
log.warn("Issue Type : " + event.getIssue().getIssueType());
WorkflowSchemeManager workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager();
String wfName = workflowSchemeManager.getWorkflowName(event.issue.getProjectObject(), event.issue.getId().toString());
log.warn("wfName : " + wfName);

def openStatusTransitionID = 131;
def adminUser = ComponentAccessor.getUserManager().getUserByName("safak.sahin");
MutableIssue issue = (MutableIssue)event.getIssue();

IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters inputParameters = issueService.newIssueInputParameters();


inputParameters.setStatusId("1").setIssueTypeId("6").setSummary("updated:" + issue.getSummary());
TransitionOptions transitionOptions = TransitionOptions.defaults();
transitionOptions.skipConditions();
transitionOptions.skipPermissions();
transitionOptions.skipValidators();

IssueService.TransitionValidationResult transitionValidationResult;
transitionValidationResult = issueService.validateTransition(adminUser, issue.getId(), openStatusTransitionID, inputParameters);
if (transitionValidationResult.isValid()) {
IssueService.IssueResult transitionResult = issueService.transition(adminUser, transitionValidationResult);
if (!transitionResult.isValid()) {
ErrorCollection errors = transitionResult.getErrorCollection();
errors.getErrorMessages().each{log.warn(it)};
errors.getReasons().each{log.warn(it)};
errors.getErrors().each{k,v -> log.warn("Key : " + k + " Value : " + v)};

}
} else {
ErrorCollection errors = transitionValidationResult.getErrorCollection();
errors.getErrorMessages().each{log.warn(it)};
errors.getReasons().each{log.warn(it)};
errors.getErrors().each{k,v -> log.warn("Key : " + k + " Value : " + v)};
}

And here is the log output:

                                                2018-01-19 15:30:36,856 WARN [runner.ScriptRunnerImpl]: issue moved
                                                2018-01-19 15:30:36,858 WARN [runner.ScriptRunnerImpl]: status : IssueConstantImpl[[GenericEntity:Status][sequence,45][statuscategory,4][name,Sales Approval][iconurl,/images/icons/statuses/generic.png][description,Sales Approve][id,10529]]
                                                2018-01-19 15:30:36,858 WARN [runner.ScriptRunnerImpl]: Issue Type : IssueConstantImpl[[GenericEntity:IssueType][sequence,1][name,Bug][iconurl,/secure/viewavatar?size=xsmall&avatarId=12853&avatarType=issuetype][description,A problem which impairs or prevents the functions of the product.][style,null][id,1][avatar,12853]]
This is the source issue Workflow not target ==>2018-01-19 15:30:36,881 WARN [runner.ScriptRunnerImpl]: wfName : TEST NP-MSU Workflow-deploymentsiz-w/o-DepUat
                                                2018-01-19 15:30:36,884 WARN [runner.ScriptRunnerImpl]: The workflow operation with action id '131' does not exist in the workflow.

 

Script Runner Listener does not work because its start just before the move event. 

Is there another way to do it? 

I'm really stuck and customer want this no matter what.

1 answer

0 votes
Tyler Brown Community Champion Jan 19, 2018

You should be able to address this issue by modifying your workflows.

Check the "Allow all statuses to transition to this one" box on your required status.

Create a group for your customers and place a permission check on the transition to the relevant status to make sure they are in the relevant group.

You may need to modify your project permissions and/or place some additional permission checks on your other transitions, but that should be able to solve your use case.

Hope this help,

Tyler

Hi Tyler,

Thanks for replying. "Allow all statuses to transition to this one" is already checked.

But that status is exist in target project workflow. What i need is no matter which status has been choosen on the move issue screen, when i move the issue it must be setted the Open status.

 

I think your suggestion did not meet my needs.

Tyler Brown Community Champion Jan 19, 2018

So you are looking for a way to force the workflow to the "Open" status whenever a customer selects any transition step in the workflow?

My initial suggestion would not solve for that problem.

Not exactly like that.

When user move issue from one project to another, user choose a workflow status from the target projects workflow right?

Now what i want is ignore user's workflow status choice and after moving operation issue always should be setted Open status.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

432 views 7 5
Join discussion

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