From 25472510db7aee98a21f9121098f4460ddc105a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20G=C3=B6rler?= Date: Wed, 5 Aug 2026 19:42:35 +0200 Subject: [PATCH] adding user description --- java/fiori-drafts.md | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/java/fiori-drafts.md b/java/fiori-drafts.md index 5c4203c30..af0dcba95 100644 --- a/java/fiori-drafts.md +++ b/java/fiori-drafts.md @@ -234,6 +234,51 @@ public void createDraft(CreateDraftContext context) { } ``` +## Showing a Custom User Description { #draft-user-description} + +By default, the SAP Fiori draft UI displays the technical user ID in fields such as *Locked by*. To show a human-readable name instead, enable the `draftUserDescription` CDS compiler option and populate the generated `InProcessByUserDescription` field via a custom handler. + +**1. Enable the compiler option** in your `.cdsrc.json`: + +```json +{ + "cdsc": { + "draftUserDescription": true + } +} +``` + +This adds `InProcessByUserDescription`, `CreatedByUserDescription`, and `LastChangedByUserDescription` to the `DraftAdministrativeData` entity. + +**2. Register a `@Before` handler** on `DRAFT_CREATE` across all draft services to populate the field: + +```java +@Component +@ServiceName(value = "*", type = DraftService.class) +public class UserDescriptionHandler implements EventHandler { + + @Autowired private UserInfo userInfo; + + @Before + protected void addDraftFields(DraftCreateEventContext context, List entries) { + CdsDataProcessor.Filter filter = + (path, element, type) -> "InProcessByUserDescription".equals(element.getName()); + CdsDataProcessor.Generator generator = (path, element, isNull) -> description(); + CdsDataProcessor.create().addGenerator(filter, generator).process(entries, context.getTarget()); + } + + private String description() { + return userInfo.getAdditionalAttribute("given_name") + + " " + + userInfo.getAdditionalAttribute("family_name"); + } +} +``` + +::: tip +The attribute names `given_name` and `family_name` correspond to JWT token claims provided by your IdP. Adjust them to match the claims configured in your environment. +::: + ## Consuming Draft Services { #draftservices} If an [Application Service](cqn-services/application-services#application-services) is created based on a service definition, that contains a draft-enabled entity, it also implements the [DraftService](https://www.javadoc.io/doc/com.sap.cds/cds-services-api/latest/com/sap/cds/services/draft/DraftService.html) interface.