Skip to main content
Skip table of contents

Reflect progress made on a todo list in a progress bar (ScriptRunner)

Prerequisites:

  • ScriptRunner running on your Jira.


Let's say you track tasks in an Elements Checklist panel and you want to display progress in a script field with a progress bar


Reflect progress of a Checklist in a progress bar


You can use the following script in a script field:


GROOVY
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.plugin.PluginAccessor;
 
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class panelContentServiceClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.content.PanelContentService");
Class panelRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.PanelRef");
Class issueRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.IssueRef");
Class attributeRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.AttributeRef");
pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.ElementsException");

def panelContentService = ComponentAccessor.getOSGiComponentInstanceOfType(panelContentServiceClass);
def PANEL_NAME = "Tasks";
def CHECKBOX_ATTRIBUTE = "Done";
 
// Define Elements panel
def panelContent;
try {
	panelContent = panelContentService.getPanel(issueRefClass.byId(issue.getId()), panelRefClass.byName(PANEL_NAME));
} catch(Exception e) {
    return '';
}
def panelItems = panelContent.getPanelItems();

if(panelItems.size() > 0) {
  def nbElements = panelItems.size();
  def nbElementsChecked = 0;
  for(def element : panelItems) {
      def isChecked = element.getAttributeContent(attributeRefClass.byName(CHECKBOX_ATTRIBUTE))?.getValue();
      if(isChecked) {
        nbElementsChecked += 1;
      }
  }
	
  def percentageDone = nbElementsChecked / nbElements * 100;
  def progress = "<progress  style=\"vertical-align:middle; max-width: 60%;\" value=\""+percentageDone+"\" min=\"0\" max=\"100\">"+percentageDone+"%</progress>"
  def spanProgression = " <span style=\"color:#999\">"+nbElementsChecked+"/"+nbElements+"</span>";
  
  return "<div>" + progress + " " + spanProgression + "</div>";
}

Notes:

  • Edit variables PANEL_NAME and CHECKBOX_ATTRIBUTE to your needs.
  • The type of the script field must be HTML
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.