0

I'm pulling in data from a SharePoint list and I'm able to successfully pull in data for the "Single text/Lookup" columns, but for some reason I'm unable to map through and pull in the People/Group columns.

Here is all the data that I am pulling in, the "Franchise Liason" column is the one that is the People or Group column that only pulls in the object. enter image description here

When I check the developer console, it maps all the way through. enter image description here

This portion throws off an error

tableContent += '<td>' + item[i].Franchise_x0020_Liason.results.map(r => r.Title).join('; ') + '</td>';

enter image description here

Here is the code:

<div id="title" style="width: 100%"></div>

<script>
$(document).ready(function() {
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('HISC Franchise Information')/items?$top=1000&$select=Title,Franchises_x0020_with_x0020_Shar/Title,Franchise_x0020_Name,DMA/Title,City,State,Region,Stand_x0020_Alone_x0020_Franchis,Franchise_x0020_Liason/Title&$expand=Franchises_x0020_with_x0020_Shar,DMA,Franchise_x0020_Liason";
    $.ajax({
        url: requestUri,
        type: "GET",
        headers: {
            "accept":"application/json; odata=verbose"
        },
        success: function(data) {
            onSuccess(data);
            ExportTable();
        }
    });

    function onSuccess(data) {
        var item = data.d.results;
        var tableContent = '<table id="TablePanel" border="1px;"><thead><tr><th>Franchise Number</th>' + '<th>Franchises with Shared Owner</th>' + '<th>Franchise Name</th>' + 
        '<th>DMA</th>' + '<th>City</th>' + '<th>State</th>' + '<th>Region</th>' + '<th>Stand Alone Franchise</th>' + '<th>Franchise Liason</th>' + '</tr></thead><tbody>';
        for (var i = 0; i < item.length; i++) {
            tableContent += '<tr>'
            tableContent += '<td>' + item[i].Title + '</td>';
            tableContent += '<td>' + item[i].Franchises_x0020_with_x0020_Shar.results.map(r => r.Title).join('; ') + '</td>';
            tableContent += '<td>' + item[i].Franchise_x0020_Name + '</td>';
            tableContent += '<td>' + item[i].DMA.results.map(r => r.Title).join('; ') + '</td>';
            tableContent += '<td>' + item[i].City + '</td>';
            tableContent += '<td>' + item[i].State + '</td>';
            tableContent += '<td>' + item[i].Region + '</td>';
            tableContent += '<td>' + item[i].Stand_x0020_Alone_x0020_Franchis + '</td>';
            tableContent += '<td>' + item[i].Franchise_x0020_Liason.results.map(r => r.Title).join('; ') + '</td>';
            tableContent += '</tr>';
            tableContent += '</tbody></thead>';
        }
        $('#title').append(tableContent);
    }

    function ExportTable() {
        $("#buttons").tableExport({
            headings: true,
            footers: true,
            formats: ["xls", "csv", "txt"],
            fileName: "id",
            bootstrap: true,
            position: "top",
            ignoreRows: false,
            ignoreCols: false,
            ignoreCSS: ".tableexport-ignore"
        });
    }
});
  • 1
    What is the error you are getting? – LeonidasFett Jan 31 at 14:47
  • What is the error thrown? Also, have you tried not doing that line all chained together, but separating it out into more discreet steps? I have found that sometimes making each step more explicit helps tease out where the problems are. – Dylan Cristy Jan 31 at 14:49
  • Are you sure that every item has a result property? Maybe SP returns null instead of an empty list when it contains no elements. In that case, you need to handle undefined for the result property in your code. – LeonidasFett Jan 31 at 15:00
  • Nvm, looks like it was defined for one specific user only, so I wasn't able to map through anyways. – SaintLouis Events Jan 31 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.