Hi,
I'm trying to create a new button via Script Fragment that will lunch a popup screen where the Jira Server , the type of Link and specific issue will be hardcoded already for the user.
Any idea how to achieve that?
thanks!
Michel
Hey, before building the fragment it's worth checking whether you need it at all. If the two instances have fully reciprocal application links, with incoming and outgoing authentication configured on both servers, the stock Link dialog already offers the remote Jira as a target and creates a real remote issue link. If the aim is just to save people picking the server and the link type every time, that's a much smaller problem than a custom dialog.
If you do want the button, the pieces are:
- A fragment of type Custom web item for the button. opsbar-operations works, though that drops it into the More menu. Use operations-top-level if you want a visible top level button and reliable access to the issue context variable.
- The setting you're after isn't a style, it's the Intention dropdown. Pick "Run code and display a dialog" and point it at a script REST endpoint. That endpoint has to return AUI dialog2 markup as text/html, so Response.ok(html).type(MediaType.TEXT_HTML).build() around a section with aui-layer aui-dialog2 aui-dialog2-medium and the usual header, content and footer divs. That's where you hardcode the server and the relationship and only prompt for what actually varies.
- On submit, create the link on your side in process with RemoteIssueLinkManager and RemoteIssueLinkBuilder rather than calling your own REST API from inside your own endpoint. If you'd rather use REST the resource is POST /rest/api/2/issue/{issueIdOrKey}/remotelink, where the only required fields are object.url and object.title.
- The part that decides whether you get a proper linked issue or just a web link is the rest of the payload. For a Jira to Jira link you want application set to type com.atlassian.jira with the remote instance name, and globalId in the form appId=<application link id>&issueId=<remote issue id>. globalId is optional in general, but here it's what ties the link to the app link. Summary and status come from object.summary and object.status.
- Worth knowing that remote links don't use Jira issue link types at all. relationship is a free text string like "causes". The stock dialog just writes the link type name into that field, and it creates a link on both instances, so if you want the same two way behaviour you need the reciprocal call on the other side too.
- For that call across, grab ApplicationLinkService with ComponentLocator.getComponent(ApplicationLinkService) and use appLink.createAuthenticatedRequestFactory(). Don't assume the authentication just works. With OAuth app links the user clicking the button has to have approved access first, and until they have you get a CredentialsRequiredException carrying an authorisation URL that you need to surface in the dialog. OAuth with impersonation avoids the per user prompt if that fits your security model.
The classic failure is skipping the app link and POSTing straight at the other instance with hand rolled credentials. The second one is sending only a url and a title, which gives you a plain entry under Web Links showing whatever title you passed, rather than a linked issue with status and summary.
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.