Get List items and output to table

Nov 11, 2015 at 6:53 PM
Hello, I'm hoping someone can help me with an issue I've been having with outputting list items to a table. I'm pulling the items and then outputting them to a table within a content editor web part for for someone reason nothing seems to be displaying. Here is what I have so far:
<script src="/SiteAssets/JQuery/jquery.min.js"></script>
<script src="/SiteAssets/JQuery/jquery.SPServices.js"></script>
<script src="/_layouts/15/SP.Runtime.js"></script>
<script src="/_layouts/15/SP.js"></script>
<script src="/_layouts/15/SP.UserProfiles.js"></script>
<script type="text/javascript">

$(document).ready(function() {
  alert("jQuery");
  alert($().SPServices.SPGetCurrentSite());


function get() {

    var method = "GetListItems";

    var webURL = $().SPServices.SPGetCurrentSite();

    var list = "Employees";

    var fieldsToRead = "<ViewFields>" + "<FieldRef Name='Title' />" + "<FieldRef Name='Users' />" + "<FieldRef Name='StartDate' />" + "<FieldRef Name='EndDate' />" + "<FieldRef Name='Status' />" + "</ViewFields>";

    var query = "<Query><Where><Eq><FieldRef Name='Target' /><Value Type=\"Text\">blank</Value></Eq></Where></Query>";
    
    



    $().SPServices

    ({

        operation: method,

        async: false,

        webURL: webURL,

        listName: list,

        CAMLViewFields: "<ViewFields Properties='True' />",

        CAMLQuery: query,

        completefunc: function (xData, Status) {

            $(xData.responseXML).SPFilterNode("z:row").each(function () {

                var Title = $(this).attr("ows_Title");

                var Users = $(this).attr("ows_Users");

                var StartDate = $(this).attr("ows_StartDate");

                var EndDate = $(this).attr("ows_EndDate");

                var Status = $(this).attr("ows_Status");


                $("#myDataTable").append("<tr align='middle'>" +

                 "<td align='left'>" + Title + "</td>" +

                 "<td align='left'>" + Users + "</td>" +

                 "<td align='left'>" + StartDate + "</td>" +

                 "<td align='left'>" + EndDate + "</td>" +

                 "<td align='left'>" + Status + "</td>" + "</tr>");

            });

        }

    });

};
});
</script>


Coordinator
Nov 12, 2015 at 11:26 AM
Edited Nov 12, 2015 at 1:06 PM
It looks like you have everything wrapped in a function called get(), which you never call! I didn't look beyond that...

BTW, you shouldn't need to load these scripts manually:
<script src="/_layouts/15/SP.Runtime.js"></script>
<script src="/_layouts/15/SP.js"></script>
<script src="/_layouts/15/SP.UserProfiles.js"></script>

M.
Nov 12, 2015 at 2:32 PM
Do you mean I shouldn't put it in a function or I need to call it somewhere else in the script?
Coordinator
Nov 12, 2015 at 6:36 PM
Either of those things. The code inside that function won't ever run unless you:
a) Call the function, or
b) put the code inline.

M.