Grid Rows Count



Grid Rows Count
import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.security.JiraAuthenticationContext import com.atlassian.plugin.PluginAccessor import com.atlassian.jira.user.ApplicationUser // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); // find TGE custom fields PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); Class tgeConfigManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.config.grid.TGEGridConfigManager"); def tgeConfigManager = ComponentAccessor.getOSGiComponentInstanceOfType(tgeConfigManagerClass); List<Long> tgeCustomFieldIds = tgeConfigManager.getGridCustomFieldIds(); // get current user JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getOSGiComponentInstanceOfType(JiraAuthenticationContext.class); Object userObject = jiraAuthenticationContext.getLoggedInUser(); User user = userObject instanceof ApplicationUser ? ((ApplicationUser) userObject).getDirectoryUser() : (User) userObject; // get row count Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager"); def tgeGridDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); result.append(tgeCustomFieldIds.size() + " TGE field found. Their configuration:\n"); for (Long tgeFieldId : tgeCustomFieldIds) { def rowCount = tgeGridDataManager.getRowCount(null, tgeFieldId, user); result.append("Grid ID=" + tgeFieldId + " has " + rowCount + " row(s) across all issues\n"); try { rowCount = tgeGridDataManager.getRowCount(issue.getId(), tgeFieldId, user); result.append("TEST-1 issue has " + rowCount + " row(s) in grid ID=" + tgeFieldId + "\n"); } catch (Exception e) { result.append("Rows of grid with ID=" + tgeFieldId + " cannot be counted: " + e.getMessage() + "\n"); } result.append("\n"); } println(result.toString()); return result.toString();