0

enter image description hereWhy is this coming back undefined if i am using the decoded list name

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    $(function () {
        $("#btnGetBoilerEFs").click(function () {

            var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('pjBoilerEmissionsCalculations')/items?";
            $.ajax({
                url: requestUri,
                type: "GET",
                headers: {
                    "accept": "application/json; odata=verbose"
                },
                success: onSuccess,
                error: onError
            });


            function onSuccess(data) {
                var items = data.d.results;

                var button1 = "click me!"
                var fullResults = '<table id="tableCars" style="width:100%" border="1 px"><thead><tr><td><b>Title</b></td>' + '<td><b>source Type</b></td>' + '<td><b>factorID</b></td>' + '<td><b>pollutantName</b></td>' + '<td><b>pollutantEFValue</b></td>' + '<td><b>pollutantEFUnits</b></td>' + '<td><b>boilerUnitID</b></td>' + '<td><b>EDIT BUTTON</b></td>' + '<td><b>DELETE BUTTON</b></td>' + '</tr></thead><tbody>';
                for (var i = 0; i < items.length; i++) {

                    var editprojinput = "<input type='button' class='contentbutton' value='Edit' onclick='EditProject(" + items[i].factorID + "," + i + ")' class='editprojbutt'/>";
                    var deleteprojinput = "<input type='button' class='removebutton' value='Delete' onclick='DeleteProject(" + items[i].factorID + "," + i + ")' class='delprojbutt'/>";

                    fullResults += '<tr>';
                    fullResults += '<td>' + items[i].Title + '</td>';
                    fullResults += '<td>' + items[i].w01u + '</td>';
                    fullResults += '<td>' + items[i]._x006f_to5 + '</td>';
                    fullResults += '<td>' + items[i]._x0070_we5 + '</td>';
                    fullResults += '<td>' + items[i]._x0074_oi + '</td>';
                    fullResults += '<td>' + items[i]._x0071_d01 + '</td>';
                    fullResults += '<td>' + items[i].boilerUnitID + '</td>';

                    fullResults += '<td>' + editprojinput + '</td>';
                    fullResults += '<td>' + deleteprojinput + '</td>';


                    fullResults += '</tr>';
                }
                $('#resultsTable').append(fullResults);
            }
            function onError(error) {
                alert('Error');
            }
        });
    });
</script>
<script>

    function EditProject(ItemID, rowID) {
        alert("hello ! " + ItemID + " and " + rowID + " I am an alert box ");
    }

</script>
<input type="button" id="btnGetBoilerEFs" value="Make Boiler EF Table" />
<br /><br />
<table id='tableCars' style="width: 100%;" border="1 px">
    <tr>
        <td>
            <div id="resultsTable" style="width: 100%"></div>
        </td>
    </tr>
</table>

enter image description here

0

Your for syntax is not correct: for (var i = 0; i "; var deleteprojinput = "";

While not undefined, your fullResults string concatenation is strange as there are no delimiters between all of the string values. It generates this:

'Titlesource TypefactorIDpollutantNamepollutantEFValuepollutantEFUnitsboilerUnitIDEDIT BUTTONDELETE BUTTON'

Lists have display names and internal names. Which is "pjBoilerEmissionsCalculations"?

  • Thats display name i believe of the list itself – Younglz2312 Oct 16 at 21:22
0

My guess is you have some of the internal names of the fields wrong.

Clearly Title, which you have as items[i].Title and sourceType, which you have as items[i].w01u are returning the correct values. Which makes me think that if all the rest are undefined, it's because those properties, at least as you have them listed in your code, do not actually exist on the JSON that's getting sent back to you.

I'd throw a console.log(items) in there and take a look at what's actually getting returned to you, and make sure for those other columns you are using the correct property name from the returned JSON.

  • thanks you helped a lot – Younglz2312 Oct 17 at 17:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.