on 04-06-2021 9:53 AM
We have an entity TechnicalObjects as below:
entity TechnicalObjects {
...
virtual status : String(10);
...
isAtCustomer: Boolean;
isAvailable : Boolean;
isInWarehouse : Boolean;
isAssignedToDelivery : Boolean;
isMarkedForDeletion : Boolean;
isInstalled : Boolean;
isAllocToSuperiorEquip : Boolean;
isInactive : Boolean;
hasSubOrdinateEquipment : Boolean;
isDeleted : Boolean;
}
Only of the above boolean values will be TRUE. Value of status should be calculated based on which attr is true. For eg, if isAvailable = true, then status value should be AVAILABLE.
My question is:
Is this possible in ODATA v4? if yes, how do we write it using CDS annotations?
Took below approach to resolve this issue. Thanks for the support guys!
https://github.wdf.sap.corp/fiori-elements/v4-consulting/issues/1173
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That link will be accessible only to the sap employees, please share the solution by taking a screenshot or by copying the text.
megha.kumari02 you can try creating a view like below using a case statement.
using my.bookshop as my from '../db/data-model';
service CatalogService {
entity Books as select from my.Books {
*,
case when stock = 100 then true else false end as testfield : Boolean
};
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi megha.kumari02,
you can use a after read handler for calculating fields.
You can find an example in the CAP Community Repository.
dj.adams.sap has also written a blog post about it.
Regards
Simon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure if you need annotations to do this, you could just use the CASE statement in your view?
CASE table.column_XXX
WHEN 'X' THEN 'Positive label'
ELSE 'Negative label'
END AS is_XXX
Or if only one of the columns can be true
CASE
WHEN table.column_01 = 'X' THEN 'Status 01'
WHEN table.column_02 = 'X' THEN 'Status 02'
WHEN table.column_03 = 'X' THEN 'Status 03'
WHEN table.column_04 = 'X' THEN 'Status 04'
END AS overal_status
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.