[ ] Enhancement
[x ] Bug
[ ] Question
v1.1.0 - I am using the segmented pnp/sp library
To have the FileRef property returned from a CAML query GET.
Does not return FileRef property.
import { sp } from "@pnp/sp";
The following will return an array of the items, but each one does not have the specified FileRef property:
const viewFields =
"<ViewFields>
<FieldRef Name='Alt_x0020_Text' />
<FieldRef Name='AlternateThumbnailUrl' />
<FieldRef Name='FileRef' />
<FieldRef Name='ID' />
<FieldRef Name='Title' />>
</ViewFields>";
const queryOptions = "<QueryOptions><ViewAttributes Scope='RecursiveAll'/></QueryOptions>";
sp.web.lists.getByTitle("Media").getItemsByCAMLQuery({
ViewXml: "<View>"+viewFields+camlQuery+queryOptions+"</View>"
}).then(media => { console.log(media); });
This should return a FileRef property just like a regular get() using select() would:
sp.web.lists.getByTitle("Media").items.select("Alt_x0020_Text", "AlternateThumbnailUrl", "FileRef", "ID", "Title").get().then(media => { console.log(media); });
The latter returns the FileRef with no issues. The former does not.
Hey @drewcook,
There are some typos in the provided code snippet, like >> or using " as if it were template string quotes. Yet I suppose that it's just an artifact of copying and pasting to the issue body.
getItemsByCAMLQuery method suppose expands. In case of FileRef it should be passed to the expands. Check the sample below:
import { sp } from '@pnp/sp';
const viewFields = `
<ViewFields>
<FieldRef Name='Alt_x0020_Text' />
<FieldRef Name='AlternateThumbnailUrl' />
<FieldRef Name='FileRef' />
<FieldRef Name='ID' />
<FieldRef Name='Title' />
</ViewFields>
`;
const queryOptions = `<QueryOptions><ViewAttributes Scope='RecursiveAll'/></QueryOptions>`;
const camlQuery = '';
sp.web.lists.getByTitle('Documents')
.getItemsByCAMLQuery({
ViewXml: `<View>${viewFields}${camlQuery}${queryOptions}</View>`
}, 'FileRef')
.then(console.log)
.catch(console.log);

@koltyakov Thank you, that is definitely working for me! I did not see any detailed documentation on the method, as it is kind of lacking. I did not know that there was a second optional parameter that could be passed in that would represent expands. Furthermore, there was no documentation stating that FileRef in particular (or any others for that matter like ContentType, etc) would need to be expanded when using the method.
The documentation is lacking for a good portion of the library. We love using it on our team but it could be better.
Thank you for the help!
@drewcook - yes the documentation can always be improved but we are constrained on time as we are all working this as a side project. Any help you can give towards improving the docs is very welcome and appreciated. Rightly or wrongly updating docs seems to always fall behind answering questions, adding features, and fixing bugs. Thanks for your interest in the library and appreciate your feedback.
Going to close this as answered, please to _reopen_ should we need to continue the conversation. Thanks!
Most helpful comment
Hey @drewcook,
There are some typos in the provided code snippet, like
>>or using"as if it were template string quotes. Yet I suppose that it's just an artifact of copying and pasting to the issue body.getItemsByCAMLQuerymethod supposeexpands. In case ofFileRefit should be passed to the expands. Check the sample below: