Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,297,914
Community Members
 
Community Events
165
Community Groups

when deleting unused screens using groovy scripts given by atlassisan i am getting the error.

https://confluence.atlassian.com/clean/advanced-cleanup-1018789335.html

 

when i am trying to perform the activity  i am getting the error at the below statement

def viewFieldScreens = new ViewFieldScreens(fieldScreenManager, fieldScreenFactory, fieldScreenSchemeManager, workflowManager)

 

can some one help

Static type checking] - Cannot find matching method com.atlassian.jira.web.action.admin.issuefields.screens.ViewFieldScreens#<init>(com.atlassian.jira.issue.fields.screen.FieldScreenManager, com.atlassian.jira.issue.fields.screen.FieldScreenFactory, com.atlassian.jira.issue.fields.screen.FieldScreenSchemeManager, com.atlassian.jira.workflow.WorkflowManager). Please check if the declared type is correct and if the method exists.

 

3. Delete unused screens:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.FieldScreenFactory
import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.issue.fields.screen.FieldScreenSchemeManager
import com.atlassian.jira.web.action.admin.issuefields.screens.ViewFieldScreens
import com.atlassian.jira.workflow.WorkflowManager

def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def fieldScreenFactory = ComponentAccessor.getComponent(FieldScreenFactory.class)
def fieldScreenSchemeManager = ComponentAccessor.getComponent(FieldScreenSchemeManager.class)
def workflowManager = ComponentAccessor.getWorkflowManager()
def viewFieldScreens = new ViewFieldScreens(fieldScreenManager, fieldScreenFactory, fieldScreenSchemeManager, workflowManager)

// use StringBuffer to spit out log to screen for ScriptRunner Console
def sb = new StringBuffer()

sb.append("Delete unused screens:\n");

fieldScreenManager.getFieldScreens().each { fieldScreen ->

 //find all screens with no (or only null/previously deleted) screen schemes or workflows
 def allEmptyOrNull = true;

 viewFieldScreens.getFieldScreenSchemes(fieldScreen).each { fieldScreenScheme ->
  if(fieldScreenScheme != null) {
   allEmptyOrNull = false;
   return;
  }
 }

 if(!allEmptyOrNull) {
  return;
 }

 viewFieldScreens.getWorkflows(fieldScreen).each { workflow ->
  if(workflow != null) {
   allEmptyOrNull = false;
   return;
  }
 }

 if(allEmptyOrNull) {
  fieldScreenManager.removeFieldScreen(fieldScreen.getId())
  sb.append("${fieldScreen.getName()}\n")
 }

}


return "<pre>" + sb.toString() + "<pre>"

2 answers

Hi @Suresh Kumar,

Please confirm if you are running on a cloud-based environment or a Server / DC environment?

If it is the former, the approach you are currently using will not work, mainly because the API is different, and there is no access to the Jira Server / DC APIs like com.atlassian.jira.component.ComponentAccessor

Thank you and Kind regards,

Ram

AnsariAn I'm New Here Jun 07, 2022

its not working on Jira Server environment.

Hi @Suresh Kumar  Welcome to Atlassian Community!

Script you are using is for JIRA Server and JIRA Data Center. It doesn't work on JIRA Cloud. 

For JIRA Cloud, I am not sure how bulk deletion work in JIRA Cloud but Atlassian is working on, you can vote this issue  :- https://jira.atlassian.com/browse/JRACLOUD-71733

Some example for bulk deletion :- 

https://github.com/cjlittle/jira-scripts/tree/main/scriptrunner-cloud

Thanks

V.Y

Vikranth our Jira is clustered environment and for deletion of workflows and other things its all working fine for deletion only for the unused screens we are facing issues.

 

with the error attached earlier. all i want is someone check the script and help me where the issue is.

def viewFieldScreens = new ViewFieldScreens(fieldScreenManager, fieldScreenFactory, fieldScreenSchemeManager, workflowManager) 

this is where i am getting error.

@Ram Kumar Aravindakshan _Adaptavist_  Kindly suggest. Following script is not working when cleaning unused screens using script console :- 

Getting error :- 

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.web.action.admin.issuefields.screens.ViewFieldScreens(com.atlassian.jira.issue.fields.screen.DefaultFieldScreenManager, com.atlassian.jira.issue.fields.screen.DefaultFieldScreenFactory, com.atlassian.jira.issue.fields.screen.DefaultFieldScreenSchemeManager, com.atlassian.jira.workflow.OSWorkflowManager)
at Script811.run(Script811.groovy:12)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.FieldScreenFactory
import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.issue.fields.screen.FieldScreenSchemeManager
import com.atlassian.jira.web.action.admin.issuefields.screens.ViewFieldScreens
import com.atlassian.jira.workflow.WorkflowManager

def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def fieldScreenFactory = ComponentAccessor.getComponent(FieldScreenFactory.class)
def fieldScreenSchemeManager = ComponentAccessor.getComponent(FieldScreenSchemeManager.class)
def workflowManager = ComponentAccessor.getWorkflowManager()
def viewFieldScreens = new ViewFieldScreens(fieldScreenManager, fieldScreenFactory, fieldScreenSchemeManager, workflowManager)

// use StringBuffer to spit out log to screen for ScriptRunner Console
def sb = new StringBuffer()

sb.append("Delete unused screens:\n");

fieldScreenManager.getFieldScreens().each { fieldScreen ->

 //find all screens with no (or only null/previously deleted) screen schemes or workflows
 def allEmptyOrNull = true;

 viewFieldScreens.getFieldScreenSchemes(fieldScreen).each { fieldScreenScheme ->
  if(fieldScreenScheme != null) {
   allEmptyOrNull = false;
   return;
  }
 }

 if(!allEmptyOrNull) {
  return;
 }

 viewFieldScreens.getWorkflows(fieldScreen).each { workflow ->
  if(workflow != null) {
   allEmptyOrNull = false;
   return;
  }
 }

 if(allEmptyOrNull) {
  fieldScreenManager.removeFieldScreen(fieldScreen.getId())
  sb.append("${fieldScreen.getName()}\n")
 }

}


return "<pre>" + sb.toString() + "<pre>"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS

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