Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to perform calculations in confluence using Jira issues count?

Manupriya S August 25, 2019

Hi,

In confluence, I want to create a table which performs certain calculations, such as: adding the two different Jira issues count. 

suppose:

I have total open issues count = 50 issues {got using the Jira Macro}

Another value that i have is, total closed = 40 issues {got using the Jira Macro}

Now i would like to perform sum on the above two Jira issues macros such that my result is:

TOTAL ISSUES = 50(Total open) +40(total closed)   

Total issues= 90

So i need to build-in something dynamic - a table which fetches the values from the Jira (using a query to look for particular issues result) and perform calculations on it.

Please help out. 

Happy to use coding and gadgets/plugins as well if possible to perform this.

Thank You

2 answers

1 accepted

0 votes
Answer accepted
DPKJ
Community Champion
August 25, 2019

@Manupriya S

You have four possibilities here,

  1. Statistics gadget,
  2. Using User Defined Macro
  3. HTML Macro and
  4. Using plugin at back-end.

Statistics gadget,

This will have some short comings, like you not see added results.

User Defined Macro/HTML Macro

  • You need to call Jira rest api and get appropriate results and display them as you like
  • This will require adding Javascript to your macro content,
  • Run the following REST query on the Confluence server to obtain JIRA's UUID (universal unique identifier):
    <Confluence URL>/rest/jiraanywhere/1.0/servers

    Which returns:

    [
      {
        id: "<UUID>",
        name: "JIRA",
        selected: true,
        url: "<JIRA URL>"
      }
    ]
  • Copy the "id" value, this is the UUID.
  • Plug that value from #2 into a standard ajax call using jQuery:
    jQuery.ajax({
      type: "GET",
      url: "<Confluence URL>/plugins/servlet/applinks/proxy?appId=<UUID>&path=<JIRA URL>/rest/api/latest/search/jql=<YOUR_JQL>",
      dataType: "json",
      async: false,
      success: function( data ) {
          //process data and render it in html tags
      }
    });

 

Back-end Plugin

Manupriya S September 9, 2019

Hi @DPKJ , Thank You very much for helping out and providing elaborations. 
I need some more help from you - can you please confirm in the above JQuery ajax code within the brackets "<YOUR_JQL>"  : so is this the Jira filter query or the java query?

Manupriya S September 9, 2019

Also, just to be sure, we are writing down this JQuery - within the HTML macro in the confluence?

DPKJ
Community Champion
September 9, 2019

JQL implies filter query that you use in Jira. Reference here - https://confluence.atlassian.com/jirasoftwareserver/advanced-searching-939938733.html

Make sure pass it in url encoded form as it contains spaces etc.

Manupriya S September 9, 2019

Hi @DPKJ  

So you mean I should have the URL link of the jira query pasted within :

<YOUR_JQL>

 

Manupriya S September 9, 2019

I will explain what I did:
In Confluence- I added the HTML Macro and pasted the code you provided above:

jQuery.ajax({
  type: "GET",
  url: "<Confluence URL>/plugins/servlet/applinks/proxy?appId=<UUID>&path=<JIRA URL>/rest/api/latest/search/jql=<YOUR_JQL>",
  dataType: "json",
  async: false,
  success: function( data ) {
      //process data and render it in html tags
  }
});

Also made changes on the code by adding the values where required(Confluence URL, Jira URL and UUID) and also added the URL link of the Jira query filter that I have. 

But I am not getting any result. Its simply the code showing up on the screen.

If you could help out much appreciated. Many Thanks

DPKJ
Community Champion
September 9, 2019

So if you want to search for issues in particular project (whose key is AA), we write this in Jira JQL Text box (i.e in advance search)

project = AA

 Now if you are using API you will replace <YOUR_JQL> with url encoded above query, i.e.

project%3DAA

 

<YOUR_JQL> is just an place holder that you have to replace with valid URL encoded JQL query that you use in Jira.

 

Here is reference guide for JQL  https://confluence.atlassian.com/jirasoftwareserver/advanced-searching-939938733.html

DPKJ
Community Champion
September 9, 2019

@Manupriya S  you have to wrap JavaScript inside script tag in macro.

Manupriya S September 9, 2019

okay can i please bother you to ask how do you convert into a url embedded code?
I have a very long query i use the advanced search for Jira queries. 

DPKJ
Community Champion
September 9, 2019

@Manupriya Syou either use this built-in JavaScript function https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI

 

Or when do you do an advance search, check your browser address bar, the part after 'jql=' is encoded JQL Query.

Manupriya S September 9, 2019

Okay Thanks a lot the seconf option worked! :) 
But now i am getting an empty screen with no result on it but it should display me 47 issues count. 

DPKJ
Community Champion
September 9, 2019

Once you are getting response, how are you processing it? You have to create one HTML element with and you have to put count in that html element using JavaScript inside callback function.

 

Can you share HTML Macro code? So that I can verify.

Manupriya S September 15, 2019

Hi @DPKJ  I will share in a while. Thanks for helping.

Priya N January 26, 2021

Hi @DPKJ  while your answer worked to fetch details in my 

Jira v8.5.9 and Confluence 7.4.5 While i try the same GET url in the 

Confluence 6.13.8 and Jira V8.5.9 it give me page not found error .

What am i doing wrong 

<Confluence URL>/plugins/servlet/applinks/proxy?appId=<UUID>&path=<JIRA URL>/rest/api/latest/search/jql=<YOUR_JQL>

Could you please let me know how to form the URL for my confleunce version  

DPKJ
Community Champion
February 1, 2021

I need to find this.

Priya N February 1, 2021

So after a lot of trial and erros if I don't use the JIRA url encoded it works. Just jql encoded 

0 votes
Fernando Guigou
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 27, 2022

Many thanks for the point about the  User Defined Macro/HTML Macro

I have used it successfully to retrieve information from Jira. 

However, now I am trying to update Jira. In particular, to transition an issue from one state to another. I have tried this, without success. Apparently, way of interacting does not support POST requests. Any suggestion?

 AJS.$.ajax({ 
url: '/plugins/servlet/applinks/proxy?appId=<appId>&path=/rest/api/2/issue/ISSUE-001/transitions',
dataType: "json",
type: "POST",
data: ({ "transition" : { "id" : "11" } }),  
context: document.body })
.done( ...

 

Suggest an answer

Log in or Sign up to answer