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
languagejava
themeEclipse
firstline1
titlereadRows usage example
linenumberstrue
collapsetrue
import com.atlassian.crowd.embedded.api.User;
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.jira.security.JiraAuthenticationContext;
import com.atlassian.plugin.PluginAccessor;
import com.atlassian.jira.user.ApplicationUser;
import org.apache.log4j.Logger;

// set up logger
Logger log=Logger.getLogger("com.idalko.scripts");

// get an issue
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("TEST-3");
Long issueId = issue.getId().toLong();

// get TGE custom field
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class);
CustomField tgeCustomField = customFieldManager.getCustomFieldObjectsByName("Grid One").get(0);
Long tgeCustomFieldId = tgeCustomField.getIdAsLong();

ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// read grid data
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class apiServiceClass = pluginAccessor.getClassLoader().findClass("com.idalko.tgng.jira.server.api.GridService");
def gridFieldData = ComponentAccessor.getOSGiComponentInstanceOfType(apiServiceClass);

StringBuilder result = new StringBuilder();
def callResult = null;

try {
    callResult = gridFieldData.readFieldData(issueId, tgeCustomFieldId, applicationUser, null);
} catch (Exception e) {
    log.error(e.getMessage())
}
    def gridRows = callResult.getRows()

for (row in gridRows) {
    def columns = row.getColumns();
    def rowId = row.getRowId();
    //log.error(columns.toString())
    StringBuilder tempResult = new StringBuilder();
    
    for (column in columns.keySet()) {
        tempResult.append("column ID: " + column + ", value: " + columns.get(column) + ", " + System.lineSeparator())        
    }
    
    result.append("Grid ID=" + tgeCustomFieldId + ", row ID: " + rowId + ", columns " + tempResult + "<br>")
}


return result;

...