How to open a create issue dialog with pre-populated fields?

Hello there,

I would like to open Jira’s create issue dialog and pre-populate fields. I want to fill in fields such as summary and description programatically.

I’ve looked at the jira-quick-edit-plugin, but it doesn’t seem to support filling in fields.

I planned on updating the fields I wanted through JavaScript since the API doesn’t support it, so I noticed that the jira-quick-edit-plugin triggers a couple of events such as “initialized” and “onContentReadyCallbacks”, but the elements in the create issue dialog are not in the DOM at the moment those callbacks are triggered.

Does anyone have an idea how I might solve this issue?

2 Likes

I wait for onReady() then I use javascript to retrieve the queryparams and set field values, so I accomplished by adding a simple plugin. Would this be useful or am I off the mark?

Thanks for your reply. I’m triggering the dialog with the following code:

var createIssue = require('quick-edit/form/factory/create-issue');
createIssue({})
.asDialog({})
.show();

I think your solution assumes opening the create issue view in a new tab. I would like to use the create issue dialog and fill in data in certain fields.

@rwhitbeck do you have any idea?

Is there anyone on the Jira Server team that we could talk to about his @nmansilla, @rwhitbeck?

Hi @f.demir ,

Whenever new content is added to a page in Jira Server, a “new content added” event is fired. Dialogs are a subset of this event’s responsibilities. You would need to create an event handler that first checked if content was added in a dialog, then if the dialog was the one you cared about.

Assuming the dialog’s ID is create-issue-dialog (please verify this, i’m literally assuming here), the following code would let you do stuff after its content was available in the DOM:

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, $context, reason) {
  // some content, somewhere, was updated.
  // let's check if it was inside a newly-opened dialog...
  if (reason === JIRA.CONTENT_ADDED_REASON.dialogReady) {
    // okay, it was *a* dialog, but was it the dialog we care about?
    if ($context.closest('.jira-dialog').attr('id') === 'create-issue-dialog') {
      // huzzah, it was the create issue dialog!
      // now we can do stuff with the contents of that dialog.
      doStuffWith($context);
    }
  }
});

The NEW_CONTENT_ADDED event has been around since at least Jira 5, so the event itself has a decent compatibility story.

With that said, there are caveats to the above code snippet!

  • It will only work for dialogs in core Jira screens.
    • It will not handle content loaded on the full issue page.
    • It will not work on service desk portal pages.
  • Jira’s fields do not have a formal API for pre-filling values on the client-side. The DOM is not a stable API, and the markup for any given field may change across versions of Jira. If you write JavaScript to find and affect them, it is not guaranteed to work across versions.

For posterity and future readers, I’ll link to some other threads where this event and similar extension use-cases have been discussed before:

Cheers,
Daz

3 Likes

Hi, in our company we also had this demand from users. I hate to be that guy, but eventually we switched to using a plugin. I wont give the direct link, but it is called Field templates for Jira. From it’s pluses, users can control it themselves, it does templates for comments as well and Allows users to have own comment templates. From the downsides, it workfs with text fields only. But for us it is quite enough. We tried other add-ons that can populate other field types but it was way too complicated. Making URL links directly was easier =)