Forum Discussion
Alex_Wadd
Feb 22, 2021Copper Contributor
Caml query not returning fileleafref
I have a CAML query that I am running through the REST api, the simple example below requests 2 fields - FileLeafRef and CustomField. Custom field is simple a text field, nothing special. Custom...
syed_nasir_abbas
Jan 12, 2022Copper Contributor
The column FileRef returns the file URL. In case of FileRef it should be passed to the expands in getItemsByCAMLQuery. Like the code:
const viewFields = `
<ViewFields>
<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);
Please note getItemsByCAMLQuery({
ViewXml: `<View>${viewFields}${camlQuery}${queryOptions}</View>`
}**, 'FileRef')**
const viewFields = `
<ViewFields>
<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);
Please note getItemsByCAMLQuery({
ViewXml: `<View>${viewFields}${camlQuery}${queryOptions}</View>`
}**, 'FileRef')**