Skip to main content
Skip table of contents

Display users associated to unchecked tasks in a user script field (ScriptRunner)

Prerequisites:

  • ScriptRunner running on your Jira.


Let's say you track tasks in an Elements Checklist panel and you want to list users that needs to take an action in a user field:



List users in unchecked tasks in user field


You can use the following script in a script field:


GROOVY
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser
 
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 attributeRefClass = pluginAccessor.getClassLoader().findClass("com.valiantys.software.elements.api.model.AttributeRef")
def userManager = ComponentAccessor.getUserManager() 

def panelContentService = ComponentAccessor.getOSGiComponentInstanceOfType(panelContentServiceClass)

// Constants to customize
def PANEL_NAME = "Tasks"
def CHECKBOX_ATTRIBUTE = "Done"
def USER_ATTRIBUTE = "Owner"

// Define Elements panel
def elementsPanel = panelContentService.getPanel(issue, panelRefClass.byName(PANEL_NAME))

// Get Elements panel items
Set<ApplicationUser> usersSet = new HashSet<ApplicationUser>()

for (def panelItem : elementsPanel.getPanelItems()) {
    def taskDone = panelItem.getAttributeContent(attributeRefClass.byName(CHECKBOX_ATTRIBUTE))?.getValue()
    if(!taskDone) {
        def owner = panelItem.getAttributeContent(attributeRefClass.byName(USER_ATTRIBUTE))?.getValue()
        if(owner != null) {
            usersSet.add(userManager.getUserByName(owner))
        }
    }

}

return usersSet

Notes:

  • Edit variables PANEL_NAME, CHECKBOX_ATTRIBUTE and USER_ATTRIBUTE to your needs.
  • The type of the script field must be User Picker (multiple users)
  • The Search of the field must be Multi User Picker Searcher
JavaScript errors detected

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

If this problem persists, please contact our support.