Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel4


Info

Check theĀ Javadoc for TGNG Java API.


Java API Examples


Code Block
languagegroovy
themeEclipse
firstline1
titlereadFieldData usage example
linenumberstrue
collapsetrue
// This script reads all data from a Grid custom field with default
// configuration named "API Sample" in issue TEST-1

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.plugin.PluginAccessor
import com.atlassian.jira.user.ApplicationUser

// Get issue id
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
Issue issue = issueManager.getIssueObject("TEST-1")
Long issueId = issue.getId()

// Get TGNG custom field id
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class)
CustomField tgngCustomField = customFieldManager.getCustomFieldObjectsByName("API Sample").get(0)
Long tgngCustomFieldId = tgngCustomField.getIdAsLong()

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Get GridService
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor()
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService")
def gridService = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass)

// Read field data
def fieldData = gridService.readFieldData(issueId, tgngCustomFieldId, user, null)
def gridRows = fieldData.getRows()

StringBuilder result = new StringBuilder()
for (row in gridRows) {
    def columns = row.getColumns()
    result.append("Order: ${columns.get("jseq")}, ")
    result.append("Summary: ${columns.get("jsummary")}, ")
    def assignee = columns.get("jassignee")
    result.append("Assignee: ${assignee == null ? "null" : assignee.get("username")}, ")
    result.append("Status: ${columns.get("jstatus")};<br>")
}

return result

...