cancel
Showing results for 
Search instead for 
Did you mean: 

CAP NodeJS remove implicit sorting on primary key

akshat_malhotra
Employee
Employee
0 Kudos

Hello ,

We are facing an issue where every service defined in CAP (Nodejs module) returns the result set in sorted order of primary key by default . We want to remove this and provide our own custom sorting . However writing an order by statement after entity select is not causing any change to the output result set and is still sorted by primary key .

From cap documentation i have read that there is some implicit sorting mechanism involved here . In JAVA runtime we can remove the implicit sorting by adding cds.query.implicitSorting.enabled: false in some config file . (https://cap.cloud.sap/docs/java/development/properties) . How do we achieve the same in NodeJS environment? Please provide the full syntax if possible as i tried adding the same as a nested structure in package.json and it didnt work .

Regards,

Akshat Malhotra

View Entire Topic
0 Kudos

Hi,

Check this documentation about implicit sorting:
https://cap.cloud.sap/docs/guides/generic#implicit-sorting

The key is always the default sort order, but if you specify other orders yourself, they have a higher priority.

BR
Samuel

akshat_malhotra
Employee
Employee
0 Kudos

This did not work as i mentioned that the custom order given in cds file was completely ignored . Not sure why

0 Kudos

Hi,

what exactly did you try? There is a sample like this:

service CatalogService {
  entity Books as projection on my.Books order by title asc;
}

Did you try this?

akshat_malhotra
Employee
Employee
0 Kudos

Writing order by clause after projection gave a syntax error . So i tried this :

service catalogService{

entity solVersion as select from table {*} order by SORTORDER;

}

This did not give any syntax error but also did not work .

epamtiosteel
Explorer
0 Kudos

Good day, sambr

what should I do if a key of an external service defined by edmx/cds is annotated by sap:sortable="false"

I have a read-only access to this service (SuccessFactors sandbox)

so I'm receiving an error error.Error during request to remote service:

[COE0003]Bad property expression: backgroundElementId; backgroundElementId is not sortable
0 Kudos

For an external service you need a custom handler anyways, so you could adjust the req.query before forwarding it to the external service, so it is not sorted anymore.