1

I'm trying to get a specific list item (by id) using JSOM and want to get all fields in this item. Though, for some of my fields I get the error that I need to request the field (which would be done @ context.load)

var slid = 3;

function retrieveListItems() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('ListName');
    this.item = oList.getItemById(slid);

    clientContext.load(item); //if you want to include something 
                              //do ctx.load(item,"Include(abc,def));

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        

}

Alright so I'm just going for context.load(item);

Is it possible to tell the context load that I really want to have all fields in the list? So I don't want to write a Include(...) line, containing 70 fields, just to be sure I get all.

How is it possible to tell the context load that I want to retrieve all fields and their values?

  • why is it not returning the values when you don't include, "Include" function parameter. Are there any fields that are null in the list in between 70 of them try debugging. – Niranjan Kulkarni Nov 5 '15 at 11:19
3

You have to explicity get all fields with

var fields= oList.get_fields();
ctx.load(fields)

you can then loop over all with

        var fieldsenum = fields.getEnumerator();
        while (fieldsenum.moveNext()) {
            var field = fieldsenum.get_current();
            var fieldname = field.get_internalName();
        }
  • Thank you. If I payed attention, I would've seen that the Internal name was not as I expected. That's why I got this error. You helped me looking into the correct values and solving the problem. – Loki Nov 5 '15 at 11:51
0

Include is used to limit the fields returned from the server. if you dont specify include all the fields are returned in the requested item. Try by inspecting your returned item object in the console.

0

Using include function only the specified properties are available after query execution. Therefore, you receive a PropertyOrFieldNotInitializedException if you try to access other properties beyond those that have been specified. In addition, you receive this error if you try to use functions such as get_contentType) or get_parentList) to access the properties of containing objects. For more information

check the links,

https://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx

https://msdn.microsoft.com/en-us/library/office/ee539350(v=office.14).aspx

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.