This project has moved and is read-only. For the latest updates, please go here.

Get List items and output to table

Nov 11, 2015 at 7: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() {

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>";



        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>");





Nov 12, 2015 at 12:26 PM
Edited Nov 12, 2015 at 2: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>

Nov 12, 2015 at 3:32 PM
Do you mean I shouldn't put it in a function or I need to call it somewhere else in the script?
Nov 12, 2015 at 7: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.