You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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:
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:
The field is empty. If we have a look at the Developer Tools we will see:
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:
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:
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.
Alexey Matveev _cPrime_
Community LeaderSoftware Developer
cPrime
Moscow
1,558 accepted answers
If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
1 comment