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");
</script>

And what I have started for the version:

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

1 answer

Hi,

I recommend installing Firebug (https://getfirebug.com/) 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 Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,531 views 15 21
Read article

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