3

I am working on a solution where I am using JSOM, I got confused on to the usage of Include in when you load the items collection, and usage of to get which fields you want? What's the specific purpose of each one?

Thanks

5

Both ViewFields query option and SP.ClientContext.load method allows to control the columns returned in result. The main difference that ViewFields query option also includes system columns. From another hand SP.ClientContext.load method allows to specify the columns strictly that will be included in result.

Example

ViewFields query option

The following query:

<View><Query></Query><ViewFields><FieldRef Name="FileRef" /></ViewFields></View>

in addition to FileRef field, the fields such as ID, Modified, Editor and some another will be included in result.

SP.ClientContext.load method

The following method demonstrates how to include only FileRef field in result:

ctx.load(items,'Include(FileRef)');

References

CAML and the Client Object Model

  • Hi Vadim, Thanks for your reply, when I used them together, I had to populate also the ViewFields with my fields, otherwise they won't appear in the query if I only use Include in the load function, I am confused about that. – SharePoint Freak Oct 4 '14 at 3:16
  • Richard, you are right,I missed it. To summarize: in order to select the list of specific fields both the ViewFields query option and fields names for SP.ClientContext.load method have to be specified. – Vadim Gremyachev Oct 4 '14 at 9:35
  • 1
    I would disagree, only the view fields need to be specified, if you omit the Include, it will still work, so why the need of the Include if I use viewfields?? – SharePoint Freak Oct 4 '14 at 14:16
  • 1
    If you specify ViewFields option, then also columns specified in ViewFields plus system columns will be returned in result. If, in addition to ViewFields option, you specify columns to retrieve in Load method, than only that columns will be returned in result. – Vadim Gremyachev Oct 6 '14 at 6:27

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.