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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,559,491
Community Members
 
Community Events
184
Community Groups

Atlassian Jira. Admin evolution. Part 5

Part 4

This solution should be avoided at all cost!

A bit more JSP

One thing left. I set the Approver as manager1 all the time, but I need to get the manager for the reporter from my user_managers table. How to do it?

Again we can create a jsp page. Let's call this page getmanagerforuser.jsp with the following code:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
try {
   String reporter=request.getParameter("reporter");
   response.getWriter().write("{\"reporter\":\""+ reporter+ "\",\"manager\":\"manager1\"}");

}   catch(Exception e)  {
}
%>

This code gets the url parameter which is called reporter and produces a json where the value of the reporter field is the value of the url parameter and the value of the manager field is manager1. Let's call this jsp page:

Screenshot 2020-06-09 at 19.41.07.png

As you can see I passed the myreporter value as the reporter parameter and the json file contains the value of the passed parameter.

Good! Now we need to call our jsp page from our JavaScript code. We will pass the value of the reporter field and we will get the manager. We can do it with the following JavaScript line:

            $.get( "/jira/getmanagerforuser.jsp?reporter="+ $("optgroup#reporter-group-suggested > option:selected").val(), function( data ) {
                 $("#customfield_10300").val(data.manager);
            });

In this line we call the getmanagerforuser.jsp, we pass the value of the reporter field and get the manager. Let's open the create issue screen:

Screenshot 2020-06-09 at 19.59.17.png

The field is empty. If we have a look at the Developer Tools we will see:

Screenshot 2020-06-09 at 20.05.35.png

The jsp page was called correctly. The reporter parameter has the value admin and it is correct. Let's have a look at the response:

Screenshot 2020-06-09 at 20.07.17.png

As you can see our json is just a part of an html content and we need to cut the json from the content. Lets cut it. Here is the code:

 $.get( "/jira/getmanagerforuser.jsp?reporter="+ $("optgroup#reporter-group-suggested > option:selected").val(), function( data ) {
                 var startIndex = data.indexOf("<section id=\"content\" role=\"main\">") +34;
                 var endIndex = data.indexOf("</section>", startIndex);
                 var str = data.substring(startIndex, endIndex);
                 $("#customfield_10300").val(JSON.parse(str.trim()).manager);
            });

And now if we create an issue we will see that the Approver field has the manager1 value:

Screenshot 2020-06-09 at 20.20.33.png

Here is the final JavaScript code:

<script>
      setInterval(function(){ 
         if ($("optgroup#reporter-group-suggested > option:selected").val()) {
            $.get( "/jira/getmanagerforuser.jsp?reporter="+ $("optgroup#reporter-group-suggested > option:selected").val(), function( data ) {
                 var startIndex = data.indexOf("<section id=\"content\" role=\"main\">") +34;
                 var endIndex = data.indexOf("</section>", startIndex);
                 var str = data.substring(startIndex, endIndex);
                 $("#customfield_10300").val(JSON.parse(str.trim()).manager);
            });

            
            $("#customfield_10300").focus(function() {
                 this.blur();
            });
         }
      }, 3000);
      setInterval(function(){ 
         if ($("#customfield_10300-val").text()) {
           if (JIRA.Users.LoggedInUser.userName() != $.trim($("#customfield_10300-val").text())) {
            $('#action_id_11').addClass('hidden');
           }
         }
      }, 3000);
</script>

And now we need to change our getmanagerforuser.jsp so that the manager would be taken from our database table. I will not provide this code, but you know how it can be done.

At last the jsp part and js part are over. Only one requirement left.

Part 6

1 comment

M Amine
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 26, 2020

good to know.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events