cancel
Showing results for 
Search instead for 
Did you mean: 

Behavior validation messages are not displayed

PatrickAngevare
Explorer
0 Kudos
524

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. 

 

abhiperiwal
Participant
0 Kudos

Hi Patrick,

I'm having the same issue. Were you able to resolve it? 

Thanks,

Abhishek

abhiperiwal
Participant
0 Kudos

Hi Patrick,

I'd appreciate if you can let me know if you were able to solve this issue. I'm having the same issue where the preview version from eclipse shows the validation errors correctly but after creating the app in BAS and after deployment, the validations errors are not shown on the UI. I am using precheck update to display the messages for now but I'd prefer to handle it using validations as it should be.

I'm on S/4 HANA on premise, ABAP 2022.

@Andre_Fischer, please provide your inputs.

Thanks,

Abhishek

GauravGaurav
Discoverer
0 Kudos
In my case Messages are displayed when %state_area is removed, but still fields are not highlighted.

Accepted Solutions (0)

Answers (1)

Answers (1)

GauravGaurav
Discoverer

In my case Messages are displayed when %state_area is removed, but still fields are not highlighted.

kyo_choi2
Participant
0 Kudos
Can you debug and check following line? %element-ProductName= if_abap_behv=>mk-on ) TO reported-product.