cancel
Showing results for 
Search instead for 
Did you mean: 

Behavior validation messages are not displayed

PatrickAngevare
Explorer
1,444

Validation error messages in a behavior implementation are not displayed and elements are not highlighted. 

In the behavior implementation for a draft enabled RAP based Fiori Elements application there is a custom check for mandatory fields. If a mandatory field is not filled, an error message should be displayed and the relevant element should be highlighted. The validation is executed correctly and the save action is stopped but only a generic error message ("Resolve data inconsistencies to save changes.") is displayed and no field is highlighted. When the app runs in preview mode via the Service Binding in Eclipse, the validation messages are correctly displayed and the relevant fields highlighted. The issue only occurs if the app runs in the Fiori Launchpad.

Behavior definition: 

managed implementation in class zbp_i_product unique;
strict ( 2 );
with draft;

define behavior for ZI_Product alias product
persistent table za_product
draft table zd_product
authorization master ( instance )
lock master
total etag LastChangedAt
etag master LastChangedAt
{
  create;
  update;
  delete;

  field ( mandatory ) ProductName;
  field ( readonly, numbering : managed ) ProductUuid;
  field ( readonly ) CreatedBy, CreatedAt, LastChangedBy, LastChangedAt;

  validation validateMandatoryFields on save { field ProductName create; }

  mapping for za_product
    {
      ProductUuid = product_uuid;
      ProductName = product_name;
      ProductType = product_type;
      CreatedBy = created_by;
      CreatedAt = created_at;
      LastChangedBy = last_changed_by;
      LastChangedAt = last_changed_at;
    }

  draft determine action Prepare
  {
    validation validateMandatoryFields;
  }
  draft action Edit;
  draft action Activate optimized;
  draft action Discard;
  draft action Resume;

}

Behavior implementation: 

CLASS lhc_product DEFINITION INHERITING FROM cl_abap_behavior_handler.
  PRIVATE SECTION.
    METHODS validatemandatoryfields FOR VALIDATE ON SAVE
      IMPORTING keys FOR product~validatemandatoryfields.
ENDCLASS.


CLASS lhc_product IMPLEMENTATION.
 METHOD validatemandatoryfields.
    READ ENTITIES OF /zi_product IN LOCAL MODE
         ENTITY product
         FIELDS ( ProductName )
         WITH CORRESPONDING #( keys )
         RESULT DATA(products).

    LOOP AT products ASSIGNING FIELD-SYMBOL(<product>).
      APPEND VALUE #( %tky        = <product>-%tky
                      %state_area = 'VALIDATE_MANDATORY' )
             TO reported-product.

      IF <product>-ProductName IS INITIAL.
        APPEND VALUE #( %tky = <product>-%tky ) TO failed-product.
        APPEND VALUE #( %tky              = <product>-%tky
                        %state_area       = 'VALIDATE_MANDATORY'
                        %msg              = new_message( id = `ZPRODUCT`
                                                         number = 009 
                                                         severity = if_abap_behv_message=>severity-error )
                        %element-ProductName= if_abap_behv=>mk-on ) TO reported-product.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.

ENDCLASS.

The Fiori app is created as a Fiori Elements List Report based on an OData V4 service. 

 

View Entire Topic
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

The code shown worked for me on a SAP BTP ABAP Environment system (latest release 2502).

I had however to perform a few changes because when using cut and paste syntax errors were shown.

1. Not sure why we see a "slash" here:

READ ENTITIES OF /zi_product IN LOCAL MODE

2. In the BDEF in the validation statement a semicolon is missing

validation validateMandatoryFields on save { field ProductName create; }

must read

validation validateMandatoryFields on save { field ProductName; create; }

And I saw

Andre_Fischer_0-1739560495683.png

 

Question: 
You have not mentioned on which release you are working ?