I wrote a query to Read list items and a specific column value like this

var invoiceitemID = SPUtility.GetSPField('ID').GetValue();
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Invoices');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>'+ invoiceitemID +'</Value></Eq></Where></Query></View>'); 
var listItems = oList.getItems(camlQuery);
var e = listItems.getEnumerator();
while (e.moveNext()){
     Netamount = listItems.get_item('Nettobetrag');

But this is not working.

2 Answers 2


After loading the items, the query needs to be executed and then the result should be parsed in the success handler. Example:

function retrieveListItems(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Announcements');

    var camlQuery = new SP.CamlQuery();
        '<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
        '<Value Type=\'Number\'>1</Value></Geq></Where></Query>' + 
    this.collListItem = oList.getItems(camlQuery);

        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() + 
            '\nTitle: ' + oListItem.get_item('Title') + 
            '\nBody: ' + oListItem.get_item('Body');


See this for more information: https://msdn.microsoft.com/en-us/library/office/jj163201.aspx

  • Thank you Nadeem. The caml query works for number or text fields but its not working for lookup column like this var Belegnummer = SPUtility.GetSPField('Belegnummer').GetValue(); var camlQuery1 = new SP.CamlQuery(); camlQuery1.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'AttachedToInvoiceID\'/><Value Type=\'Lookup\'>'+ Belegnummer +'</Value></Eq></Where></Query></View>'); Something wrong with Query ?. Apr 27, 2015 at 21:03

Rather than write (and debug) your own query, I would recommend using the GetListItems function of the SPServices library. If you're using JavaScript, it's super easy to implement both jQuery and the SPServices library to get some awesome & much-needed functionality.

Once you have the libraries loaded on your page (I usually put them in my master page), getting the items in a list (full or filtered) can be done with a single snippet of code:

<script language="javascript" type="text/javascript">

$(document).ready(function() {
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";

For more info, see http://spservices.codeplex.com/wikipage?title=Lists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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