Skip to Content
0
May 31, 2023 at 03:52 PM

OData $nextlink fetching duplicate data via CAP for external service

321 Views Last edit May 31, 2023 at 04:03 PM 6 rev

Hi Experts David Kunz Gregor Wolf

We are fetching data from external service in our CAP custom handler.
But $nextlink fetches duplicate data.


I fear it is fetching data as a new session/call eachtime we call this.apiService.get(`/${nextlink}` which results in duplicate data.

Putting an orderBy on key field gives the right data not duplicates, probably because even in a new call/session data remains sam due to sorting.

Below is the code snippet. Kindly Help.

//Package.json    
"MAS": {
"kind": "odata", 
"model": "srv/external/MAS", 
"credentials": { 
"destination": "DESTINATION", 
"path": "/EntitySet", 
"query": 
{ "sap-client": "100" 
} } }
//Custom Handler
this.apiService = await cds.connect.to(‘MAS');
let result = await this.apiService.run(query);
if (result === undefined) {
return result;
}
if (Array.isArray(result))
this.AllData.push(...result);
else if (result instanceof Object)
this.AllData.push(result);
while (result.$nextLink) {
var nextlink = result.$nextLink;
result = [];
result = await this.apiService.get(`/${nextlink}`);
this.AllData.push(...result);
}
return this.AllData;

Thanks

Kanika