Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Change status without a transition Edited

UPDATED - "searchResults" needed to be updated.

I wanted to create a script that would change the status of an issue without having to transition it. After a lot of searching and head banging, I was able to create a groovy script that I can run in the Script Console in ScriptRunner. This script accepts two inputs.

1 - A JQL to provide the script with a list of issues that it needs to modify.  

2 - The destination status you want the issues in.

The script will loop through the issues and "migrate" the issues into the status you Identified. 

I have found this extremely helpful for issues that get "stuck" in statuses that have no way out. I hope it will help others.

 


/*****************************
Purpose: This script is used to change the status of issues regardless of were they are in the workflow. No transition is needed to move an issue into another status. However, The destination status has to reside in the workflow.
Author: Kevin Bouman
Date: 08/06/2019
Updated: 12/26/2020 Kevin Bouman (Added instructions for updating the resolutions)
*****************************/

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.workflow.WorkflowManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.config.ConstantsManager;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.util.ImportUtils;

def searchService = ComponentAccessor.getComponent(SearchService.class);
def issueManager = ComponentAccessor.getIssueManager();
def constantsManager = ComponentAccessor.getConstantsManager();


//********************** VARIABLES ******************************

//Place the name of the Destination status
def destinationStatusName = "Approved";

/****************
If you need to update the Resolution of an issue please refer to the "ScriptRunner" Built-In-Scipt called "Bulk Fix Resolutions".
- Update the "Fix - Resolution" JQL to grab the issues you need to update the resolution for.
- Navigate to the "Bulk Fix Resolutions" built-in-script
- Select the "Fix - Resolution" JQL that you just updated.
- Select the resolution you want to update the issues to.
- Run the script
****************/

//Define the JQL to get the issues you want to affect
def jqlQuery = 'key = PRISK-613';

//********************** ********* ******************************

//Results array
def results = [];

//Get the current user
JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
def user = authContext.getLoggedInUser();

//Run the JQL
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlQuery);
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());

//create the list that contains all the issue keys
def issues = searchResult.results.collect {issueManager.getIssueObject(it.id)};

//Loop through the list of results from the JQL.
for (MutableIssue i in issues){

//Get the workflow
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager();

def workflow = workflowManager.getWorkflow(i);
def workflowName = workflow.getName();

//Create map to store return values
def issueMap = [:];

def currentStatusName = i.getStatus().getName();

//Check if the current status is the same as the destinationStatus
if (currentStatusName != destinationStatusName){

//Get Destination Status Object
def destinationStatus = constantsManager.getStatusByName(destinationStatusName);

//Migrate issue with WorkflowManager
workflowManager.migrateIssueToWorkflow(i, workflow, destinationStatus);

//Update the issue in the DB
issueManager.updateIssue(user, i, EventDispatchOption.DO_NOT_DISPATCH, false)

//log.warn("The status of ${i.key} was changed from $currentStatusName to $destinationStatusName")

//Add to map
issueMap.put("issue", i.getKey());
issueMap.put("result", "The status was changed from $currentStatusName to $destinationStatusName");
}
else {
//Add to map
issueMap.put("issue", i.getKey());
issueMap.put("result", "The status of " + i.getKey() + " was not changed");
}

//Reindex the issue
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
log.warn("Reindex issue ${i.key} ${i.id}")
issueIndexingService.reIndex(i);
ImportUtils.setIndexIssues(wasIndexing);

//Add map to results array
results.add(issueMap);

}

return results

 

1 answer

Hello,

This could be very helpfull in some cases, I try to use it but gives some errors 

example:

//create the list that contains all the issue keys
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)};

Any solution? 

@Nicolás Figueroa 

I updated the code to use "searchResults.results.collect" instead of "searchResults.issues.collect". It should work for you now.

Like Nicolás Figueroa likes this

Oh this is great!

Thanks for your quick response @Bouman , Im always wandering how to solve this errors in Script, you just take a look in the libraries and update it?

Ya you can look at the documentation. A huge resource for me is the Atlassian community. You can find a lot of other scripts that use pieces that you might need. I treat them like Legos... plug and play. However that can get you in trouble so it is best to use both the community and documentation. Its also good to keep in mind that Cloud can be very different than Datacenter.

Like Nicolás Figueroa likes this

Thanks a lot for your advice,

I really explore the community but not always have the time to find the correct answers,

Have a great week!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Jira issue check and more advanced commit verifications for Bitbucket DC

Pre-receive hooks that verify the Git commit message, the modified files, and implement similar code change controls used to be requirements of large enterprises working in regulated industries only....

56 views 0 3
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