Skip to Content
Oct 19, 2020 at 12:43 PM

Implementing a beforeUpdate handler


Hey Capire Experts,

I have a basic issue in understanding how an UPDATE (Http PATCH) call works and how to implement a corresponding BEFORE/ON Handler.

A Http PATCH sends the changed Data to the backend only, which seems reasonable. The primary key of the entity to be changed is part of the URL (e.g.: " ... PATCH Item(7addeaa8-71f0-4e1e-93ce-f9e71e6414c5) ... " ).

The request payload to change the "item_text" of an entity called "item" looks like this:


PATCH Item(7addeaa8-71f0-4e1e-93ce-f9e71e6414c5) HTTP/1.1

X-CSRF-Token: (....)

{"item_text":"Changed Item Data"}


However, when implementing an UPDATE Handler using the POJO Interface like this:

	@Before(event = CdsService.EVENT_UPDATE, entity = Item_.CDS_NAME)
	public void beforeUpdate( Item item ) {
		log.debug( "Item primary key: " + item.getId( ) );
		if ( item.getItemText( ).equals( CHANGED_ITEM_TEXT ) ) {
			item.setItemText( DERIVED_ITEM_TEXT );

there seems no straightforward way to find out the ID (7addeaa8-71f0-4e1e-93ce-f9e71e6414c5) of the item being updated . All fields of "item" are null, except for "item_text"; so "item.getId( )" will fail.

When I try to use the "CdsUpdateEventContext" I also receive "modifiedAt" and "modifiedBy" , but again no primary key:

	@Before(event = CdsService.EVENT_UPDATE, entity = Item_.CDS_NAME)
	public void beforeUpdate( CdsUpdateEventContext ctx ) {
		Item item = ctx.getCqn( ).asUpdate( ) ).single( Item.class );
		log.debug( "Item primary key: " + item.getId( ) );

Am I doing this completely wrong?

How is this supposed to work?

How do I find out the primary key of the entity ?

kind regards

Reinhard Jaeschke