3

I need to get all my custom fields from my list by Javascript Object Model..

The code I wrote down is this:

var items;
    $(document).ready(function () {
        $("[name=ItemChildCount]").text("Figli");
         var context = SP.ClientContext.get_current();
         var list = context.get_web().get_lists().getByTitle('Codice Ragione Sociale');
         var camlQuery = SP.CamlQuery.createAllItemsQuery();
         items = list.getItems(camlQuery, 'Ragione Sociale');

         context.load(items);

        context.executeQueryAsync(Function.createDelegate(this, onListDataSucceeded), Function.createDelegate(this, onListDataFailed));  
    });

    function onListDataSucceeded(sender, args) {

        var listItemEnumerator = items.getEnumerator();


        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();

            alert(oListItem.get_item('Title') + oListItem.get_item('Ragione Sociale'));
        }

    }

    function onListDataFailed(sender, args) {

        alert('List Data fetch failed. ' + args.get_message() + 'n' + args.get_stackTrace());
    }

When I arrive on oListItem.get_Item('Ragione Sociale') system told me the column is not loaded... But I told the system to load it on getItems!

3
  • 1
    Did you try Internal Name? :)
    – eirikb
    Sep 28, 2012 at 11:01
  • 2
    eirikb's comment is likely the issue. You can determine the field's internal name by going to the properties page for the list, right clicking on the field, selecting properties and in the URL all the way at the end you will see Field=InternalName. Just remember that underscore is encoded in the URL as %5F so Field=Link%5Fx0020%5Fto%5Fx0020%5FTemplate is Field=Link_x0020_to_x0020_Template. See here: isurinder.com/blog/post/2011/06/01/… Sep 28, 2012 at 12:34
  • A post on this subject [Good SharePoint JavaScript Client Object model use example for beginners][1] [1]:sharepointbreak.com/2013/07/22/…
    – Guy Perry
    Aug 13, 2013 at 16:21

1 Answer 1

2

In JavaScript, you specify Include as part of the query string that is passed to the load(clientObject) method in order to specify which properties to return. The following example uses this approach to return only the title and ID of each list in the collection.

 clientContext.load(collList, 'Include(Title, Id)');

If solution not work then please remove space in field name that may problem.

See this msdn post http://msdn.microsoft.com/en-us/library/hh185009.aspx

2
  • Thank you! I use the Include and removed the space! Everything works fine ;)
    – Ziba Leah
    Sep 28, 2012 at 13:34
  • Noteworthy that it requires the internal name. So for a column 'Due Date' it would most likely look like this: Include(Due_x0020_Date). Jul 27, 2017 at 14:03

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.