Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

Any suggestion?

Thank you very much!

share|improve this question
1  
Did you try Internal Name? :) –  eirikb Sep 28 '12 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/… –  Robert Kaucher Sep 28 '12 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 '13 at 16:21
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
Thank you! I use the Include and removed the space! Everything works fine ;) –  Ziba Leah Sep 28 '12 at 13:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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