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.
Community moderators have prevented the ability to post new answers.
So I found a way to get the current Issue ID/Key. Here's how I did it:
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.
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.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"); });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Daniel,
As @paul said , please elaborate your main objective on the basis of which a better solution can be provided.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
May I please know, what was the final solution to it? I have to fetch the issue key using groovy.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.