Read Grid data for All Issues



Read Grid data for All Issues
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.getIssueManager(); 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.getJiraAuthenticationContext(); Object userObject = jiraAuthenticationContext.getLoggedInUser(); User user = userObject instanceof ApplicationUser ? ((ApplicationUser) userObject).getDirectoryUser() : (User) userObject // read the grid data Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager"); def tgeGridDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); for (Long tgeCustomFieldId : tgeCustomFieldIds) { try { def callResult = tgeGridDataManager.readAllGridDataForAllIssues(tgeCustomFieldId, null, null, 0, 10, user); result.append("Grid ID=" + tgeCustomFieldId + " content: " + callResult.getValues() + "\n"); } catch (Exception e) { result.append("Grid ID=" + tgeCustomFieldId + " data cannot be retrieved: " + e.getMessage() + "\n"); } } println(result.toString()); return result.toString();