Setting a screen's fixVersion via JS

Hi All,

I'd like to set the initial fixVersion of a screen via JS. I'm doing the same to set the assignee to the current user(as opposed to automatic). The only problem is I don't know the JS code to set the fix version field. Does anyone know the proper form?

For reference, this is is what I use for assignee:

<script type="text/javascript">
    var fixVersionsSelect = AJS.$("#fixVersions"); 
    fixVersionsSelect.trigger('set-selection-value', "10006");

And what I have started for the version:

<script type="text/javascript">
    var fixVersionsSelect = AJS.$("#fixVersions"); 
    fixVersionsSelect.trigger('set-selection-value', "version #");

1 answer


I recommend installing Firebug ( or equivalent, if you're going to be tinkering with Javascript. Then in JIRA load the "create issue" page, F12 to launch Firebug and "inspect" the Fix Version/s element. In my JIRA it is a textarea with id "fixVersions-textarea". Then switching to the Firebug Console, I can type AJS.$("#fixVersions-textarea").val("3.0"), and can see it sets the value.

Unless this is a quick once-off hack, I wouldn't recommend this approach of using Javascript to preset field values. It won't take effect for issues created by email, or by SOAP or REST. It's also very brittle, as Atlassian make no guarantees about the HTML or Javascript structure of pages. I'd rather install the Groovy plugin, and create a Groovy post-function that sets the assignee and/or Fix version.

Thanks Jeff, that's what I was looking for.

A couple of thoughts in response:

Fortunately we don't really need this feature anywhere else, we just want it when we are creating issues in a screen. It's mainly so when we create 20 issues or so it's defaulted to the current version.

I looked into the Groovy plugin, it might work for our purposes. One of the problems I ran into with post functions on create is that there is no conditinal check. So if a user fills out the form with values they would be overwritten by the post script. If I could do the Groovy plugin, and have a script that said 'if the current version is not set, set it to the default' that would be ideal.

The best possible solution would be to have default values definable for each screen. We just want to be able to define some default values for the screens when users are filling in data. I suppose I'll make a ticket for that!

Drat, so after using this, it seems like there's still a snafu. It sets the field, but since Jira uses those label objects, it doesn't get added to the ticket. Unfortunately it doesn't seem like there's a way to 'set' the fix version. Time for a feature request!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,965 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot