2024 Oct 18 8:40 PM - edited 2024 Oct 18 8:47 PM
Hello,
I'm using CAP with typescript and I have defined a draft-enabled entity SystemKinds. Cds-Typer is installed and Typescript types will be generated and updated each time I change my entity definition.
If I send a GET request with SystemKinds , I can see all properties of entity SystemKinds plus the draft properties IsActiveEntity, HasActiveEntity,HasDraftEntity. On sqlite database, I also see the auto-generated tables AdminConfigServices_SystemKinds_drafts and the DRAFT_DraftAdministrativeData with its properties e.g. InProcessByUser. Both tables are linked via DraftUUID.
Now, I like to display InProcessByUser in Fiori Elements list report and the date of last modification. Therefore, I try to extend my entity with these two properties. I don't know how to get access to these properties inside a READ handler. In other words, how do I get access to these auto-generated tables ? The approach with SystemKind.drafts does not work as documented in Fiori Support | capire (cloud.sap). Typescript does not know SystemKind.drafts or SystemKinds.drafts. It is not available in the type definition in folder @CDS-models.
Here is my AdminConfiguration.ts:
import cds from '@sap/cds';
import { SystemKind, SystemKinds } from '#cds-models/AdminConfigurationService';
class AdminConfigurationService extends cds.ApplicationService {
/** Registering custom event handlers */
init() {
// extract entities
const { SystemKinds } = this.entities
// Extend draft information
this.after('READ', SystemKinds, async( response ) => {
// here, i like to extend response with the properties LastChangedByUser from DRAFT_DraftAdministrativeData
// and HasDraftEntity from AdminConfigurationService_SystemKinds_drafts
}
}
Request clarification before answering.
Hello,
my packag.json encounters the following:
"devDependencies": {
"@cap-js/cds-typer": ">=0.1",
"@cap-js/cds-types": "^0.6",
"@cap-js/sqlite": "^1",
"@sap/ux-specification": "UI5-1.129",
"@types/node": "^20",
"@sapui5/types": "^1.116",
"@ui5/cli": "^4.0.8",
"typescript": "^5"
}
If I do the following, I will get the DraftAdministrativeData as follows:
let AvailEntities: cds.entity[] = [SystemKinds, SystemKinds.drafts];
srv.after('READ', AvailEntities, async (response) => {
if (!response) return;
....
const currentUser = cds.context?.user.id;
.....
response.forEach((singleEntity: any) => {
....
let IsCreatedByMe : Boolean = singleEntity.DraftAdministrativeData.DraftIsCreatedByMe;
let InProcessBy : String = singleEntity.DraftAdministrativeData.InProcessByUser;
});
});
For the SystemKinds.drafts , there is no TypeScript type auto-generated. The draft administrative data can be accessed by the entity's DraftAdministrativeData property.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you are right:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stephen,
I saw this git commit today on the cds-type package and felt this would be the relevant update for you.
The draft properties are added to the type definition.
https://github.com/cap-js/cds-typer/pull/354
Regards,
Arun K
User | Count |
---|---|
78 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.