Forum Discussion
noel43
Aug 16, 2023Copper Contributor
Issue while posting the request to Sharepoint list which has more than 5000 items.
Hi,
I am using below code for my spfx soution to post my caml and getting beow 500 error.
private getOpenstatus()
{
let _openCount: string = '';
let val="In Progress";
let camlQueryPayLoad: any = {
'query' :
{
'__metadata':
{ 'type': 'SP.CamlQuery' },
"ViewXml": "<View><Query><Where><Eq><FieldRef Name='Status' /><Value Type='Text'>"+val+"</Value></Eq></Where></Query><ViewFields><FieldRef Name='ID' /></ViewFields><QueryOptions /><RowLimit>5000</RowLimit></View>"
}
};
let spOpts = {
headers: { 'odata-version': '3.0' },
body: JSON.stringify(camlQueryPayLoad)
};
const queryString: string = "$select=ID&$filter=Status eq '"+val+"'";
let url: string = this.context.pageContext.web.absoluteUrl + `/_api/web/lists/getbytitle('IncidentDetails')/GetItems?$top=5000`;
return this.context.spHttpClient
.post(url,
SPHttpClient.configurations.v1, spOpts)
.then((response: SPHttpClientResponse) => {
let lvlFive: string = '';
if (response.status === 404) {
//Log.error('js-display-List', new Error('List not found.'));
return [];
} else {
if (response.ok) {
response.json().then((responseJson) => {
console.log(responseJson);
if (responseJson != null) {
let length= responseJson.value.length;
_openCount +=`<a class="nav-link active" data-toggle="tab" href="#open-incident">Open<span>(<span>${length}</span>)</span></a>`;
this.domElement.querySelector('#openCountView').innerHTML = _openCount;
//this.domElement.querySelector('#levelFive').innerHTML = lvlFive;
}
});
}
}
});
}
Below is the Response from API with 500 code.
{
"odata.error": {
"code": "-2147024860, Microsoft.SharePoint.SPQueryThrottledException",
"message": {
"lang": "en-US",
"value": "The attempted operation is prohibited because it exceeds the list view threshold."
}
}
}
"odata.error": {
"code": "-2147024860, Microsoft.SharePoint.SPQueryThrottledException",
"message": {
"lang": "en-US",
"value": "The attempted operation is prohibited because it exceeds the list view threshold."
}
}
}
Could you please help me how can I fix it ? I need an urgent help and would be great if i can get the quick solution.
No RepliesBe the first to reply