Forums

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

Create html tabel from JSON jira rest api on confluence page

Alex October 22, 2019
<table  class="confluenceTable", id="projectListTable">
  <tr>
    <th class="confluenceTh" >Key</th>
    <th class="confluenceTh" >Name</th>
    <th class="confluenceTh" >Lead</th>
</tr>
</table>
<script>
$.ajax({
    url: confluence/plugins/servlet/applinks/proxy?appId=ID&path=jira/rest/api/2/project?expand=lead',
    type: "get",
    dataType: "json",
  
    success: function(project) {
        drawTable(project);
    }
});


function drawTable(project) {
    for (var i = 0; i < project.length; i++) {
        drawProjectRow(project[i]);
    }
}
function drawProjectRow(rowProject) {

    var row = $("<tr/>")
    $("#projectListTable").append(row);
    row.append($("<td class=\"confluenceTd\" >" + rowProject.key + "</td>"));
    row.append($("<td class=\"confluenceTd\" >" + rowProject.name + "</td>"));
row.append($("<td class=\"confluenceTd\" >" + rowProject.lead[0] + "</td>"));
}
</script>

Hi i'm trying to create dynamic table.
In column Lead getting "undefined"
And tell me how to make a link to the project from the key =)

 

1 answer

1 accepted

1 vote
Answer accepted
Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2019

Hi @Alex ,

I believe lead is not an array but it is JSON object with key, name and displayName fields. So you need to use not rowProject.lead[0] but e.g. rowProject.lead.displayName instead.

To make a link you just need to concatenate your base url with project key to get something like

<a href="http://localhost:8230/projects/rowProject.key">rowProject.name</a>

Suggest an answer

Log in or Sign up to answer