Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Atlassian Jira. Admin evolution. Part 9

Part 8

Javascript: Common sense changes

Well, we have a not bad solution for our mapping table. Let's have a look at our Javascript.

First of all we have the following problems:

  • sometimes our browser freezes
  • there is a delay between the button Ready For Work is hidden or value manager1 is set for the Approver field.

Our setInterval function causes this problems.

Let's change setInterval function somehow. For example, to make a delay less noticeable we can decrease the waiting period for the interval function. But in this case our function will work more often which will cause more freezes to our browser. What next? We should make our setInterval smarter. Let's say make it smarter for hiding the "Ready For Work" button. We need to hide our button only once, if the button is hidden, we should not try to hide this button again. Here is how the code looks like:

var hideActionInterval = setInterval(function(){ 
         if ($("#customfield_10301-val").text()) {
           if (JIRA.Users.LoggedInUser.userName() != $.trim($("#customfield_10301-val").text())) {
           } else {
      }, 3000);

We added clearInterval(hideActionInterval) after we made our choice to hide the button or not.

Well, can we do the same for our Approval field? No, we cant. Because if we stop our interval and after it we will change the value for the Reporter field, the new value for the Approver field will not be set. What to do?

The problem is that our approach with setInterval is completely wrong. We should execute our functions to hide the button after all elements were loaded. Same for setting a value for the Approver field. We need to set a value after all elements were loaded and after the value for the Reporter field was changed.

Ok, how to understand that all elements were loaded to a page? In jquery we could write something like this:

 $(function() {
         if ($("#customfield_10301-val").text()) {
           if (JIRA.Users.LoggedInUser.userName() != $.trim($("#customfield_10301-val").text())) {

We used $(function() {}) to wait until the page has been loaded. And it worked for the "Ready for Work" button. Well, let's do the same for the Approver field:

      $(function() {
         if ($("optgroup#reporter-group-suggested > option:selected").val()) {
            $("#customfield_10301").focus(function() {

And it did not work? Why? Because when we push the create button the announcement banner is not reread and as a result nothing works. Any ideas how to fix it?

Of course, let's add our JavaScript to the description of our Approver field. A custom field's description is always loaded for the Create issue screen.


Ok. Let's try again. And it did not work. This method does not work in the newest versions of Jira, but it worked before. Anyway even if it worked, do you consider it a good solution? I do not. Because your JavaScript code is now in several places in Jira. How a new administrator or you six months later are going to look for all JavaScript code? You would need to write some kind of program right? Then how would a new administrator know that you have this program? You will document it? Are you sure that your program is not buggy and will work for the new Administrator?

Too many questions with awkward answers. It seems like we are going to do something wrong.
Let's think again. Any ideas? To search in Google? We could but still how would I know that it is a good solution?

At this point I have only one idea to look for an answer in the source code of Jira. At last I am there!

Before I looked for solutions after examining pages in the Developer Console and as a result I created all those bad solutions with JavaScript. But the right way to look for solutions in the source code. Only if you understand how Jira works, you can create a good solution! If your developer or administrator looks for solution in the Developer console, then I believe that your JavaScript solutions will be of a very low quality.

Ok. Let's have a look at the code. Atlassian provides the source code of Atlassian Jira for users who bought a Jira license.

Part 10

1 comment

M Amine Community Leader Sep 29, 2020


Log in or Sign up to comment

Atlassian Community Events