0

I'm trying to get access to the name in the first component for each issue and don't seem to be able to figure this out. There will only ever be one item in the component array. In this case it should return me "KBR" Here's my code:

<script>
// Gets the data related to items added in sprint pi-19.3
$(document).ready(function() {
    $.getJSON("./json/PI-19/taxonomyAddedAfterSprintStart.19.3.json", function(data_add) {
        var  jira_data_add = '';

        $.each(data_add.issues, function(key, val){
            jira_data_add += '<tr>';
            jira_data_add += '<td>'+val.key+'</td>';
            jira_data_add += '<td>'+val.fields.issuetype.name+'</td>';
            jira_data_add += '<td>'+val.fields.summary+'</td>';
            jira_data_add += '<td class="centered-cell">'+val.fields.customfield_10013+'</td>'; // Story Points Custom Field
            jira_data_add += '<td class="centered-cell">'+val.fields.status.name+'</td>';
            jira_data_add += '<td class="centered-cell">'+val.fields.components.name+'</td>';
        });

        jira_data_add += '</tr>';

        $('#sprint-items-added-pi-nineteen-c').append(jira_data_add);
    });
});
</script>

Here's the JSON

"issues": [
    {
      "expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
      "id": "1286516",
      "self": "https://xxx",
      "key": "TAXY-662",
      "fields": {
        "components": [
          {
            "self": "https://xxx",
            "id": "40920",
            "name": "KBR"
          }
        ],
    }

I've also tried:

jira_data_add += '<td class="centered-cell">'+val.fields.components[0].name+'</td>'; 

This does not work - I get undefined back

I've also tried:

jira_data_add += '<td class="centered-cell">'+val.fields.components["name"]+'</td>'; 

Again I get undefined back in the table

Ignacio Ara
  • 2,476
  • 2
  • 26
  • 37
  • Your JSON has issues. It's not valid, most likely a typo, can you fix it? – mmdts Apr 20 '18 at 16:48
  • `val.fields.components[0].name` should have worked. But there's no `val.fields.issuetype` or `val.fields.summary` in the JSON you posted. It looks like you've left part of it out, so how are we supposed to know how those properties are formatted? – Barmar Apr 20 '18 at 16:48
  • val is coming from the function $.each(data_add.issues, function(key, val) - so it's not part of the JSON structure itself. I do get the data back when I use val in the other cases like jira_data_add += ''+val.fields.summary+''; – Rich Meadows Apr 20 '18 at 17:37

0 Answers0