Need to delete more than 100 Inactive/Draft workflows.
Wondering if there is there a automated way to achieve this, via any scripting methods ?
Well I do it the way that Atlassian might not suggest: directly on the database itself. There is a table call Workflow_Draft (or something like that ) that I can just run a delete statement and then I just reindex the whole JIRA and restart the program. It works for me (in 4.4.1). But again, anything directly to database is not recommended, I guess I have just been lucky.
If you have the ScriptRunner plugin, the following script will delete all inactive workflows for you, ignoring the "classic' workflow.
import com.atlassian.jira.component.ComponentAccessor def workflowManager = ComponentAccessor.workflowManager def schemeManager = ComponentAccessor.workflowSchemeManager def sb = new StringBuffer()workflowManager.workflows.each {if(!it.systemWorkflow) {def schemes = schemeManager.getSchemesForWorkflow(it)if (schemes.size() == 0) { sb.append("Deleting workflow: ${it.name}\n") workflowManager.deleteWorkflow(it) } }}
return sb.toString()
Note this will not delete inactive schemes, only inactive workflows. Modifying this to find inactive schemes should be possible.
A quick note: system default workflow should be assigned to some scheme, otherwise script won't work.
Thank you so much.It work for me using Yevgen suggestion.
Unfortunately ScriptRunner is no longer free, but has gone commercial / expensive, so many people can't follow the suggestion.
It's frustrating to Admins and harmful to Atlassian's reputation that so many problems (including some horrible spots in the UI, such as this Delete Workflow UI or the user picker) can only be solved by spending a lot of money on plugins.
For those of you who would like to avoid buying ScriptRunner just for this clean up task, have a try with this awesome solution: https://gist.github.com/zionyx/378ba519239bf040b2a6310b68d2740d
You are most welcome.
you're awesome!!
Works fine with Safari.
I have created a simple script that you can execute it in chrome. No need to install or pay anything.
Execute it until you get rid of all deleteable workflows.
function deleteNext(){ waitAndClick('#inactive-workflows-module-heading h3', () => { waitAndClick('[data-operation="delete"]', () => { waitAndClick('[name="Delete"]') }) }) document.querySelector('[data-operation="delete"]').click() document.querySelector('[name="Delete"]').click()}function waitAndClick(selector, callback) { const el = document.querySelector(selector); if (el) { el.click(); return (callback) ? callback() : null; } return setTimeout( () => { waitAndClick(selector, callback); }, 100);}deleteNext()
Got Syntax error
Worked for me in Chrome
nice. I needed to add some semi colons...
function deleteNext(){waitAndClick('#inactive-workflows-module-heading h3', () => {waitAndClick('[data-operation="delete"]', () => {waitAndClick('[name="Delete"]');})})document.querySelector('[data-operation="delete"]').click();document.querySelector('[name="Delete"]').click();}function waitAndClick(selector, callback) {const el = document.querySelector(selector);if (el) {el.click();return (callback) ? callback() : null;}return setTimeout( () => {waitAndClick(selector, callback);}, 100);}deleteNext();
If you're running Jira Cloud and you'd like to delete all the workflows that Jira is willing to allow you to delete, then consider running the following script in ScriptRunner:
// Get a list of the first N Workflows (appears that N is max of 50)Map<String, Object> searchResult = get('/rest/api/3/workflow/search') .queryString("maxResults", "200") .asObject(Map) .bodydef w = (List<Map<String, Object>>) searchResult.values// Iterate over all the Workflows; Attempt to delete everyone :eek:w.each { if (it.id.entityId != null) { println "Attempting to delete: ${it.id.entityId} - ${it.id.name}" def hr = delete('/rest/api/3/workflow/'+ it.id.entityId).asString() println hr }}
If you'd like to delete all the unreferenced Workflow Schemes, try this snippet:
// Get a list of the first 200 Workflow SchemesMap<String, Object> searchResult = get('/rest/api/3/workflowscheme') .queryString("maxResults", "200") .asObject(Map) .bodydef ws = (List<Map<String, Object>>) searchResult.values// Iterate over all the Workflow Schemesws.each { // Only want the Workflow Schemes without any mappings if (it.issueTypeMappings.size() == 0) { println "Deleting: ${it.id} - ${it.name}" def hr = delete('/rest/api/3/workflowscheme/'+ it.id).asString() println hr }}
I've posted these in my GitHub Repo for forking and updating goodness.
I hope this saves you a couple hundred clicks, hours of your life, and puts a little smile on your face when you are making thankless changes cold and alone in the depths of Jira. Please enjoy the hours this puts back in your life doing anything other than Jira Administration. You've earned it.
It looks like you're new here. Sign in or register to get started.