How to get an issue ID?

Mykhailo April 28, 2016

Hello!

I want to integrate Calculated Text field with Table Grid Editor (TGE). TGE team provides Java API for Script Runner. But I want to use it with your plugin. I wrote the following script base on their "Get Grid Data Script" (https://wiki.idalko.com/display/TGPD/Read+Grid+Data).

<!-- @@Formula: 
// configuration
String tgeCustomFieldName = "TGE_SRC";
String summaryColumnName = "isummary";
Object pluginAccessor = com.atlassian.jira.component.ComponentAccessor.getPluginAccessor();
Object dataManagerClass = pluginAccessor.getClassLoader().loadClass("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager");
Object tgeGridDataManager = com.atlassian.jira.component.ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass);
Object jiraAuthenticationContext = com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext();
Object customFieldManager = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager();
Object tgeCustomField = customFieldManager.getCustomFieldObjectByName(tgeCustomFieldName);
Long tgeCustomFieldIdLong = tgeCustomField.getIdAsLong();
Object userObject = jiraAuthenticationContext.getLoggedInUser();
Object user = userObject instanceof com.atlassian.jira.user.ApplicationUser ? ((com.atlassian.jira.user.ApplicationUser) userObject).getDirectoryUser() : (com.atlassian.crowd.embedded.api.User) userObject;
Set columnNames = new HashSet();
columnNames.add(summaryColumnName);
Object issueId = issue.get("issueid");
Object callResult = tgeGridDataManager.readGridData(issueId, tgeCustomFieldIdLong, null, columnNames, 0, 10, user);
callResult.getValues();
-->

It is ugly, but it worked until I tried to get issue ID using "issue.get("issueid");" expression that was found in the comments to the documentation here (https://innovalog.atlassian.net/wiki/display/JMCF/JIRA+Misc+Custom+Fields). But it does not work! It tells me

2016-04-28 15:52:21,748 http-nio-2990-exec-3 ERROR admin 952x134074x1 x8516 127.0.0.1 /secure/AjaxIssueEditAction!default.jspa [c.i.jmcf.fields.CalculatedTextField] CalculatedTextField: error evaluating formula of field "calculated" of issue OTH-1: 
    Sourced file: inline evaluation of: ``   // configuration  String tgeCustomFieldName = "TGE_SRC";  String summaryColum . . . '' : Typed variable declaration : Method Invocation issue.get : at Line: 17 : in file: inline evaluation of: ``   // configuration  String tgeCustomFieldName = "TGE_SRC";  String summaryColum . . . '' : issue .get ( "issueid" ) 
    
    Target exception: java.util.NoSuchElementException

It looks, that "issue.get ( "issueid" ) " is not an acceptable way to get the issue ID. How can I get the issue ID?

JIRA Misc Custom Fields: 1.7.1

JIRA: 7.1.4

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2016

Hi Michael,

as documented here, the issue key is accessed through the "issuekey" field. Now, if what you need is the issue ID (a Long), you need to use the following instead: issueObject.getId()

Hope this help,

David

Mykhailo May 4, 2016

Yep. It worked!

I also wonder if there any way to get import classes into script to avoid using full names with package prefix?

Also why doesn't it allow to use generics?

David _old account_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 4, 2016

First of all, you can indeed "import" classes using the import statement (as long as the class is visible from the add-on's classLoader, which has limited visibility because add-ons are OSGi plugins somewhat isolated for the JIRA core).

Now, the reason why you cannot use generics is because the scripting language used by JMCF is BeanShell, which supports a limited Java syntax.

BTW, your question pertains to JIRA Misc Custom Fields (JMCF) not JIRA Misc Workflow Extensions (JMWE) - you should update the tag in your question. In JMWE, you would use the Groovy syntax which is much more sophisticated (even more than Java itself).

Mykhailo May 4, 2016

Thank, David!

You are right. I can import classes. I updated the question tag.

0 votes
Henry Baez May 4, 2016

     -  issueObject.getId()Homebrew/homebrew

TAGS
AUG Leaders

Atlassian Community Events