Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get Issue Name and a String from the Details field

DanielM
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.
July 14, 2013

The things I need to get

So this is part of what our issues in Jira look like. I'm making a plug-in, and I need to fill some variables with the current issue's Name and another one with a part of the string in External issue URL, but I don't know how to get those two strings.

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
DanielM
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.
July 22, 2013

So I found a way to get the current Issue ID/Key. Here's how I did it:

  1. I opened atlassian-plugin.xml and added a webitem(button), that points to my servlet;
  2. At the linkId I set the path to my servlet and added ?id=${issueId};
  3. In my servlet's doGet methid I called
    req.getParameter("id")

    where req is an HttpServletRequest;

    <web-item key="my_Buttons_Button" name="Button in Issue"
    		section="transitions-all" weight="30">
    		<label>Extract Revisions</label>
    		<link linkId="my_Buttons_Button">http://localhost:2990/jira/plugins/servlet/helloworld?id=${issueId}</link>
      </web-item>

    Above is the code for the webitem. I hope my explenation was clear enough. When you have the Issue ID you can get the Issue key and other values through the IssueManager.

    Here is some sample code for getting the Issue key:

    String id = req.getParameter("id");
    Long idl = Long.parseLong(id);
    String key = issueManager.getIssueObject(idl).getKey();

    Hope this saves you people some trouble.

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 23, 2013

Nice you found a way (which I think was answered before in the comments, maybe we werent clear enough ^^)

Instead of the Id you could use the issue directly in the plugin.xml:

${issue.key}

In your case I would choose a REST-Service instead of a Servlet (Annotations, Injection, etc.)

DanielM
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.
July 23, 2013

Sorry, I'm quite new to all this and didn't really understand what you were saying, I see now that I kind of did the same thing you suggested, if you post it as an answer I'd be happy to accept it as one.

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 23, 2013
No problem :)
1 vote
Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 15, 2013

Somehow you have to trigger your backend, therefore you can call a REST-Services and send the issue-key:

1. Get the key via JS

2. Create a Web-Item with an URL to a REST-Service (get the Issue-Key with ${issue.key})

<web-item key="" name="" section="operations-top-level" weight="10">
  <label key="" >This is a Label</label>
  <link linkId="google_home">http://localhost:2990/jira/browse/${issue.key}</link>
</web-item>

It would help, if you explain what you want to achieve, maybe there is a smarter solution :)

DanielM
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.
July 23, 2013

I don't want to create a new question for this, I've checked a few similar questions but it didn't help me.
I wanted to ask, is there some line of code I can add to the webitem, to make it open in a new window/tab?

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 23, 2013

I think you are right, there is no direct way in the web-item to do it.

I would do it with a little javascript:

jQuery("#your_id_here").click(function(){
  jQuery("#your_id_here").attr("target", "blank");
});

DanielM
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.
July 23, 2013

How should I add that script to my code? I mean I can add it to the (let's call it helloworld.js) plugin's javascript file, but how do I trigger it? Can you explain to me a bit better how I can use that javascript code?

EDIT: I made gave the button a <styleClass>issueaction-log-work</styleClass> and it now opens a dialog with the results, but I'd still appreciate it if you could explain to me how to add the javascript to the webitem.

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 23, 2013

Yeah, you can add it to "helloworld.js". Read the articel about web-resource-modules.

Its triggered by .click() when you click the link.

To add the binding you can use this (JIRA.bind workes if content is reloaded via AJAX):

AJS.$(document).ready(function() {
        //Your code here
    });

    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {
       //Your code here
    });
1 vote
Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 15, 2013

Hi Daniel,

as Dipti explained, you need the IssueObject, which you can access via the IssueManager.

// Via Injection
IssueManager im = ...

Issue myIssue = im.getIssueObject("TEST-1");
Issue myIssue2 = im.getIssueObject(10101);
String key = myIssue.getKey();
...

Or you can access some values via JavaScript in the frontend

var base_url = AJS.params.baseURL;
var key = AJS.Meta.get("issue-key");
var id = AJS.$("input[name='id']").val();

But I am also not sure what exactly you are looking for,

greetz paul

0 votes
DanielM
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.
July 15, 2013

OK, so what I'm doing is I'm creating a plug-in that will update the machine generated comments for the git commits in a Jira Issue by adding an additional line of text to them.

So I need to make some git requests, which I form by iterating through the bodies of only the machine generated comments in the current Issue. So I need to be able to get the current Issue's key automatically when I press an Update button, so the plug-in can fill the value for the IssueObject and get all its comments so I can iterate through them and extract the info I need.

The info from the custom field (External Issue URL) is also needed so I can form the git request.

0 votes
Dipti Ranjan Behera
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.
July 15, 2013

@Daniel,

As @paul said , please elaborate your main objective on the basis of which a better solution can be provided.

0 votes
DanielM
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.
July 15, 2013

Well, basicly when I press a button on the plug-in when I'm in the current Issue, I need to be able to automatically extract the current Issue key/id and fill this x variable:

MutableIssue iss = issueManager.getIssueObject(x);

So I don't want to have to instantiate an issueObject with some parameter like ("TEST-1") and then call the getKey, I want to be able to get the Key of the Issue that's on my screen right now.

0 votes
Dipti Ranjan Behera
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.
July 15, 2013

Hi Daniel,

can you explain your query in more detail?

But from what i understood , check this API link : https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/Issue.html

two methods (getKey , getCustomFieldValue ) , it will help you.

Nishant Kansal April 11, 2016

May I please know, what was the final solution to it? I have to fetch the issue key using groovy.

Thanks

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events