0

I am learning to build custom SP solution with JS and HTML following the Apress book of same name.

I use the following script (in Code Snippet of a SEWP):

<script type="text/javascript">

$(function () {
    $.ajax({
        url: "/_api/web/lists/GetByTitle('Tills')/items?$select=Till/Title&$expand=Till&$filter=Till/Title%20eq%20'Main'
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose"
        },
    }).success(function (data) {
          var listItemInfo = "<h2>There are " + data.d.results.length + " items in table.</h2><table style='align:left'><tr><th>Number</th><th>Till</th><th>POS</th><th>IP</th><th>Type</th><th>Version</th></tr>";

        $.each(data.d.results, function (key, value) {
            listItemInfo += "<tr><td style='width:100px'>" + value.Number + "</td><td style='width:100px'>" + value.Till + "</td><td style='width:100px'>" + value.POS + "</td><td style='width:100px'>" + value.IP + "</td><td style='width:100px'>" + value.Type + "</td><td style='width:100px'>" + value.Version + "</td></tr>";
        });
        listItemInfo += "</table>";
        $("#tills").html(listItemInfo);
    });
});
</SCRIPT>

to display results of the Tills Custom List (in the div with ID 'tills' in a CEWP).

Some of the fields show data as expected (Number, POS, IP, Version) but Till and Type show as 'undefined. They like most other fields are defined as 'Single Line of Text' with the default values.

I tried adding a $select and $expand to the query string, but Fiddler gives Error 400 with message

The field or property 'Till' does not exist.

Any suggestions please?

0

Only simple values (numbers, strings, dates) are brought back by default. If you want the other values you need to explicitly request them by using $select. You will most likely need to also use $expand to get object or collection property values.

You should get used to using a tool like Fiddler to see what the response coming back from SharePoint looks like. Anything with __deferred underneath the property name means the value was not returned by default.

enter image description here

  • HiThanks for suggestion re Fiddler. I've heard of it but not used it yet. – Craig Jul 1 '15 at 21:24
  • I added select and expand - see above - but get error 400. From MS docs expand is for JOINs, but the undefined fields are not in a projected list. "When a SharePoint list has a lookup field to another list, this effectively serves as a join of the two lists. You can use the $expand option to return projected fields from the joined list." – Craig Jul 2 '15 at 6:50
0

The answer to my problem turned out to be the List itself. Recreating the list shows all fields. (I am not clear on what was wrong with the way it was first created.)

Fiddler is a great tool to use, so thanks Rob for the tip.

0

One thing I want to add if you face again this kind of problem, try to use alphanumeric name of the fields as sometimes it fails to recognize these user created column names.

For shortcut just press F12 and select the column which is not find by the compiler.

You would get something like this,

displayname="JobTitle" fieldtype="Text" SortField=**_x006e_xc2**;><a class="ms-headerSortTitleLink" id="diidSort0_x006e_xc2"

Copy the text and use the same in your query.

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.