Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Active Contributor


Fiori elements list report supports the prefilling of fields with default values when creating a new entity. Users will see a popup asking for input parameters. Based on these inputs, an event handler determines the default values to be pre-filled.


This functionality is specified through the use of annotations for prefilling fields, as illustrated below:


<Annotation Term="Common.DraftRoot">
    <Record Type="Common.DraftRootType">
        <PropertyValue Property="NewAction" String=""/>


Source: Prefilling Fields When Creating a New Entity | UI5 Demo Kit

My aim is to achieve this functionality with CAP Node.js. While CAP Java documentation provides guidance on implementing this feature, there is currently no equivalent documentation for CAP Node.js.


Here goes the implementation. As you can see, it is fairly simple.

Service Definition

Service definition should follow the instructions provided in the CAP Java documentation.

  1. Define an action bound to the draft-enabled entity with an explicitly binding parameter typed with many $self.
  2. Annotate the draft-enabled entity with @Common.DraftRoot.NewAction: '<action name>'.


using { my.booklist as db } from '../db/schema';

service BooklistService {
    @Common.DraftRoot.NewAction: 'BooklistService.createDraft'
    entity Books as projection on db.Books actions {
    action createDraft(in: many $self, title: String) returns Books;


Action Implementation

The action must perform the following tasks:

  1. Set initial data.
  2. Create a draft with initial data.
  3. Return the draft.


import cds from '@sap/cds'

module.exports = class BooklistService extends cds.ApplicationService {
    init() {
        const { Books } = this.entities;

        this.on('createDraft', Books, async (req) => {  
            //set initial data
            const data =  {
                ID: cds.utils.uuid(),
                publisher: 'Test'
            //create a draft
            const book = await this.send({
                query: INSERT.into(Books).entries(data),
                event: "NEW",

            //return the draft
            return book;
        return super.init();


According to the Q&A below, CAP Node.js does not provide draft API, so srv.send() has to be used instead.


In this blog, we explored how to prefill fields with default values when creating a new entity using CAP Node.js. By defining an action bound to the draft-enabled entity and implementing this action to set initial data and create a draft, developers can effectively prefill fields in their applications.


Active Participant

That's how you create a draft!!




Another option is to use @Common.DefaultValuesFunction to define a function that returns the parameters for the new object.

Active Contributor
0 Kudos


Thank you for your suggestion! I looked into it and discovered the following blog post on the topic.

Labels in this area