cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP RAP - Trigger determination on save without field changes

saurabh__khare38
Participant
0 Kudos
3,581

Hi,

I've a RAP-based app - Managed, Draft enabled.

I've a determination at the parent entity level

determination updateInvoice on save { create; update; }

So I expect the determination to trigger on save whenever I hit save in the edit mode. The problem is the determination only triggers if I update/change the value of at least one field before hitting save.

I would like to have the determination trigger on save irrespective of whether I update any fields or not. How can I achieve that? Is there a way I can insert a dummy entity update somewhere after the user hits save to force-trigger the determination?

Regards,

Saurabh

Accepted Solutions (1)

Accepted Solutions (1)

saurabh__khare38
Participant

This can be done in the behaviour definition in draft determine action Prepare by using the keyword        ( always ) with the validation, determination that you want to trigger irrespective of the trigger condition

 

  validation simulateInvoiceUpdate on save { create; update; }

  determination updateInvoice on save { create; update; }

  draft action (features : instance) Edit;
  draft action Activate;
  draft action Discard;
  draft action Resume;
  draft determine action Prepare { validation ( always ) simulateInvoiceUpdate;
                                     determination ( always ) updateInvoice; }

 

Another way to achieve this is to have additional implementation for Edit and make a dummy change in the draft as soon as edit is clicked. This will generate the draft version as soon as edit is clicked and the subsequent save triggers the determination since the draft is updated.

 

draft action ( features : instance, authorization : update ) Edit with additional implementation;

 

 

CLASS DEF:
METHODS:
edit FOR MODIFY
        IMPORTING keys FOR ACTION invoice~edit.

CLASS IMPL:
METHOD edit.    
    DATA lt_invoice_update TYPE TABLE FOR UPDATE zfi_r_invoicetp.

    " Force draft creation with pseudo change as soon as edit is clicked
    " So that the determination works on the draft and not on the saved version
    " This helps avoid a host of problems mentioned in the note of the beh. def.
    READ ENTITIES OF zfi_r_invoicetp IN LOCAL MODE
         ENTITY invoice
         ALL FIELDS WITH CORRESPONDING #( keys )
         RESULT FINAL(lt_invoice_entity).

    lt_invoice_update = VALUE #( BASE lt_invoice_update
                                 FOR ls_invoice_entity IN lt_invoice_entity
                                 ( %tky        = ls_invoice_entity-%tky
                                   %is_draft   = if_abap_behv=>mk-on  " <=== IMPORTANT!
                                   %data-belnr = ls_invoice_entity-%data-Belnr
                                   %control    = VALUE #( belnr = if_abap_behv=>mk-on ) ) ).

" Pseudo update to trigger draft changes and eventually parent determination on save
    IF lt_invoice_update IS NOT INITIAL.
      MODIFY ENTITIES OF zfi_r_invoicetp IN LOCAL MODE
             ENTITY invoice
             UPDATE FROM lt_invoice_update
             MAPPED DATA(ls_mapped)
             REPORTED DATA(ls_reported)
             FAILED DATA(ls_failed).
    ENDIF.

    mapped = CORRESPONDING #( DEEP ls_mapped ).
    reported = CORRESPONDING #( DEEP ls_reported ).
    failed = CORRESPONDING #( DEEP ls_failed ).
ENDMETHOD.

 

 

Answers (0)