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

Use SIL to the maximum Part 2

Part 1

Redirect Page Configuration

This menu option lets you make a smart redirection to Jira pages. You can find Vendor's information here. To tell you the truth, I spent a couple of hours to understand why we need this feature and how to use it. I feel that it is better to explain this feature with an example. Here is the example.

Suppose, each employee files invoices each month in Jira.

Screenshot 2020-05-24 at 10.00.24.png

As you can see Alexey Matveev filed two invoices for March and April.

But HR works in an external system where the payment is done and in this external system HR officer must be able to see the latest invoice, which was filed in Jira, for each employee.

Of course this HR officer can login to Jira, open Issue Navigator and filter all issues in the Invoices project by employee ordered by the Invoice Date custom field in the descending order and the first invoice will be the latest invoice.

project = INV and reporter = amatveev order by "Invoice Date" desc

But it is a too complicated approach. We would like to be able to access the latest invoice by a link in our HR system.

But what will be the link?

We can not make this link look like this: http://localhost:2990/jira/browse/INV-2. Because this invoice will be the latest in May but not the latest in June. Do we need to change this link every month in our HR system? It sounds too complicated! We need a simpler solution.

And the Redirect Page Configuration will help you here.

Let's configure it.

In our HR system we can make the link look like this:

http://localhost:2990/jira/plugins/servlet/kredi?userName=Alexey+Matveev

As you can see we call the plugins/servlet/kredi servlet which will do smart redirection for us and also we pass Alexey+Matveev as the user name parameter which will tell the servlet for which user we need the latest invoice.

Now we need to make our servlet smart. Open the Redirect Page Configuration menu and enter the following code:

string userName = argv["userName"];

if (isNull(userName)) {
    return "/plugins/servlet/kredierror?customErrorTitle=User Not Provided&customErrorMessage=Provide user with userName parameter";
}
if (isNull(getUserByFullName(userName))) {
    return "/plugins/servlet/kredierror?customErrorTitle=User Not Found&customErrorMessage=User " + userName + " not found";
}
string [] k = selectIssues("project = INV and reporter = " + getUserByFullName(userName).username + " order by \"Invoice Date\" desc");
if (size(k) == 0) {
   return "/plugins/servlet/kredierror?customErrorTitle=Invoice Not Found&customErrorMessage=No invoices for "+ userName; 
}
return "/browse/" + k[0];

The script does the following:

  • we take the value of the userName parameter which was passed in the url.
  • we check if the userName parameter was really passed. If it was not passed we redirect to the error page with the message "Provide user with userName parameter".
  • we check that a user with the user name exists in Jira. If not, we redirect to the error page with the message "User userName not found".
  • we select the latest invoice for the user. If no invoices selected, we redirect to the error page with the message "No invoices for userName".
  • we show the invoice page.

Well, let's test it!

First let's make a link like this:

http://localhost:2990/jira/plugins/servlet/kredi?userName=Alexey+Matveev

If we click on this link we will see the following screen:

Screenshot 2020-05-24 at 10.30.49.png

Correct! We were redirected to my latest invoice.

Now let's not pass the userName parameter:

http://localhost:2990/jira/plugins/servlet/kredi

And we were redirected to the error page:

Screenshot 2020-05-24 at 10.32.14.png

Correct!

Now, let's provide the user name who does not exist in Jira

http://localhost:2990/jira/plugins/servlet/kredi?userName=Super+Man

We were redirected to the error page:

Screenshot 2020-05-24 at 10.33.51.png

And now let's provide a user without filed invoices:

http://localhost:2990/jira/plugins/servlet/kredi?userName=Tomas+Brook

Again we were redirected to the error page:

Screenshot 2020-05-24 at 10.35.24.png

So, our program works correctly!

In short, we moved all logic for redirecting us to the correct page to Jira. And it is very handy because we can implement our logic with the SIL language which makes manipulation with Jira easy.

Part 3

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events