Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions java/fiori-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<CdsData> 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.
Expand Down
Loading