cancel
Showing results for 
Search instead for 
Did you mean: 

$Select in CAP Odata service

arjun_thakur
Active Contributor
0 Kudos

Hi Experts,

I am working on a CAP project in which i have defined an entity in my data-model.cds file and exposed that enityt as Odata in the srv module.

data-model.cds


namespace my.leads;
using { managed } from '@sap/cds/common';

entity LeadDetails : managed{

    key leadID:String(24);
    leadStatus : String(24);
    leadType :String(24);
    partnerInCharge : String(30);
    projectID : String(16);
    Region : String(10);
    Unit : String(10);
    fee : Integer;
    expenses : Integer;
    contingentFee : Integer;
    contingentExpense : Integer;
    clientID : String(10);
    clientName : String(50);
    contractValue : Integer;   
}

cat-service.cds


using my.leads as my from '../db/data-model';

@path : 'lead'
service CatalogService {
    
    entity LeadDetails @readonly   as projection on my.LeadDetails;
}

When I run the oData and use the $select, I noticed that the key field defined in my entity is always returned in the output.

In the screenshot, you can see that even though I passed $select=Region,Unit but in the output I got leadID as well which is the key field.

Is it possible to not get the key field retuned when specific columns are requested using $select in CAP.

Please advise.

Regards,

Arjun

gregorw
Active Contributor
0 Kudos

Hi Arjun,

can you explain why this is a problem at all?

Best regards
Gregor

arjun_thakur
Active Contributor
0 Kudos

Hi Gregor,

We need to use this CAP Odata service in Smart Business Service to generate some KPIs and drilldown charts. So we need to use $select in order to aggregate the measure field.

So in my case if I need to aggregate contract value based on region, I would use $select=Region,contractValue and expect an output to have contract value aggregated per unique region value. But since we are getting the key field in the output of $select, the aggregation of measure field is not working.

I hope I am able to explain my scenario.

Please let me know if you have advise to resolve this issue.

Regards,

Arjun

View Entire Topic
gregorw
Active Contributor

Hi Arjun,

thank you for the additional details. As mentioned by David you have you use the $apply parameter. Check out my examples at tests/analytics.http.

CU
Gregor