How to get fields on Screen Edited

I need to get fields on screens like Resolve Issue Screen or any other screen. 

I find the screens by the screen id comes from descriptor. Some screens has screen id and some one doesnt. How can i get screen or fields which doesnt have screen id. Or it's enough for me screen id for diffrent screen types (resolveissu, fieldscreen)

Two descriptior examples:

First

 

<action id="2" name="Close Issue" view="resolveissue">
      <meta name="opsbar-sequence">60</meta>
      <meta name="jira.i18n.submit">closeissue.close</meta>
      <meta name="jira.i18n.description">closeissue.desc</meta>
      <meta name="jira.i18n.title">closeissue.title</meta>
</action>

Second

 

<action id="111" name="Stop progress" view="fieldscreen">
      <meta name="jira.i18n.submit">stopprogress.title</meta>
      <meta name="jira.description"></meta>
      <meta name="jira.i18n.title">stopprogress.title</meta>
      <meta name="jira.fieldscreen.id">10100</meta>
</action>

The method to get screen is succes for second screen because it has a fieldscreen.id which is 10100.

 

 

FieldManager fieldManager = ComponentAccessor.getFieldManager();
FieldScreenManager fieldScreenManager = ComponentAccessor.getComponent(FieldScreenManager.class);
FieldScreen fieldScreen = fieldScreenManager.getFieldScreen(new Long(screenId));

 

 

 

1 answer

If you are looking for a way to retrieve workflow transition screen information using Groovy code, this might give you an efficient solution than XML processing:

https://shaakunthala.wordpress.com/2017/06/27/jira-groovy-where-are-osworkflow-transition-screens/

Now, answer to your question: 

Some workflow transitions may not have a transition screen (i.e. transition happens immediately when user clicks the transition button or drags story to a different column). In that case you won't see 'jira.fieldscreen.id' for that transition.

If you want to find all screens, here's the solution (try it in script console):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.*

def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def fieldScreens = fieldScreenManager.getFieldScreens()
def html = ""

fieldScreens.each { FieldScreen fieldScreen ->
def tabs = fieldScreen.getTabs()
html = html + "<h1>" + fieldScreen.name + "</h1>"
tabs.each { FieldScreenTab tab ->
html = html + "<h2>" + tab.name + "</h2>"
def items = tab.getFieldScreenLayoutItems()
items.each { FieldScreenLayoutItem item ->
if (item.getOrderableField()) html = html + "<p>" + item.getOrderableField().name + "</p>"
}
}
}
return html

If you know the screen ID, just remove 'fieldScreens.each' closure (not the contents of it), and use,

fieldScreen = fieldScreenManager.getFieldScreen (Long.parseLong(screenId))

Hope this helps.

Shaakunthala

 

Here's the Java version if it makes your life easier...

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.screen.*;
import java.lang.StringBuilder;

FieldScreenManager fieldScreenManager = ComponentAccessor.getFieldScreenManager();
Collection<FieldScreen> fieldScreens = fieldScreenManager.getFieldScreens();
StringBuilder htmlBuilder = new StringBuilder();

for ( Iterator<FieldScreen> fieldScreensIterator = fieldScreens.iterator(); fieldScreensIterator.hasNext(); ) {
FieldScreen fieldScreen = fieldScreensIterator.next();
Collection<FieldScreenTab> tabs = fieldScreen.getTabs();
htmlBuilder.append ( "<h1>" + fieldScreen.getName() + "</h1>" );
for ( Iterator<FieldScreenTab> tabsIterator = tabs.iterator(); tabsIterator.hasNext(); ) {
FieldScreenTab tab = tabsIterator.next();
htmlBuilder.append ( "<h2>" + tab.getName() + "</h2>" );
Collection<FieldScreenLayoutItem> items = tab.getFieldScreenLayoutItems();
for ( Iterator<FieldScreenLayoutItem> itemsIterator = items.iterator(); itemsIterator.hasNext(); ) {
FieldScreenLayoutItem item = itemsIterator.next();
if (!item.getOrderableField().equals(null)) htmlBuilder.append ( "<p>" + item.getOrderableField().getName() + "</p>");
}
}
}
return ( htmlBuilder.toString() );

Hi Sameer,

 

I put together few lines as script and now i am able to display all the screens used in my instance. Can you please help me in identifying only the inactive screens? This is to cleanup the unused screens in my jira instance. 
Below is the script which i have used to display the screens.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.screen.*

def fieldScreenManager = ComponentAccessor.getFieldScreenManager()
def fieldScreens = fieldScreenManager.getFieldScreens()

fieldScreens.each { println (it.name)
}

I used a similar script for workflows, where i was able to segregate the inactive workflows using its size. But couldn't find the same for screens.
if(schemes.size() == 0) {
sb.append("Deleting workflow: ${it.name}\n")
workflowManager.deleteWorkflow(it)
}

Appreciate your help.

Thanks
Deepa

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira

How you can achieve compact and easy-to-maintain workflows in your JIRA( Server)

This approach requires you to have the JIRA administrative rights. The main aim of this article is to help you achieve an organized, easy-to-maintain workflows in your JIRA instance thereby, reducin...

189 views 0 0
Read article

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