Lookup Manager
Breadcrumbs

How to identify the workflows that are using Lookup Manager

Scenario

Instead of going through every workflow and find where the app is being used, the user can use ScriptRunner to identify the workflows that are using Lookup Manager post functions.

How-to

Step 1:Go to ScriptRunner Console

image-20210607-052458.png

Step 2: Copy and paste the code below into the console

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.plugin.workflow.AbstractWorkflowModuleDescriptor
import com.atlassian.jira.workflow.JiraWorkflow
import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.plugin.PluginAccessor

import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

import java.util.regex.Matcher 

PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()

//Lookup Manager has 4 post functions
//1. LookupPostFunction
//2. LookupEntityPostFunction
//3. LookupReversePostFunction
//4. RemoveEntityPostFunction
String searchText = 'com.akelesconsulting.jira.plugins.jira.workflow.LookupPostFunction'

Collection<JiraWorkflow> workflows = workflowManager.getWorkflows()

String result = "Workflow; Action; <br>"

workflows.each{workflow ->
    //log.debug("Checking workflow name = [" + workflow.getDisplayName() + "]")
    def workflowXml = workflow.descriptor.asXML()
    Matcher m = workflowXml =~ /${searchText}/
    
    if (m.find()) {
        String workflow_name = "${workflow.name}${if(!workflow.isActive()){"(inactive)"} else ''}${if(workflow.isDraftWorkflow()){"(draft)"} else ''}"
        log.debug("Workflow name = [" + workflow.getDisplayName() + "]")
        def wf = new XmlParser().parseText(workflowXml)
        List<Node> wf_flat = wf.depthFirst()
        wf_flat.each{            
            if (it.text() ==~ /.*${searchText}.*/){
                def nodeInfo = getNodeInfo(it,searchText)
                if (nodeInfo){
                    result += "$workflow_name;$nodeInfo<br>"
                }
            }            
        }
    }
}

result


String getNodeInfo(Node n, String search) {
    String nodetext = ''
    def valid_action = false
    def valid_function = false
    def valid_step = false
    if (n.name() == 'function') {       
        def p = n.parent()
        while (p) {
            switch (p.name()) {
                case 'post-functions':
                    valid_function = true; break;
                case 'action':
                    valid_action = true
                	log.debug(" 	--> ${p.attribute('name')} (${p.attribute('id')});")
                    nodetext += " ${p.attribute('name')} (${p.attribute('id')});"; 
                	break;
            }
            p = p.parent()
        }        
    }
    
    if (valid_action && valid_function) {
        return nodetext
    } else {
        return ""
    }
}


Step 3: Verify

Check the Logs

image-20210607-051909.png

Check the Result

image-20210607-051937.png