cancel
Showing results for 
Search instead for 
Did you mean: 

Smartfield -dropdown annotation help - only ID no description

0 Kudos

Hi!

I have followed every guide and discussion, but my problem still persists, so I seek out help here myself.

I have implemented annotation in frontend for SmartField dropdown.

<Collection>
 <Record Type="Common.ValueListParameterOut">
   <PropertyValue Property="LocalDataProperty" PropertyPath="CountryOfOrigin"/>
  <PropertyValue Property="ValueListProperty" String="CountryId"/>
 </Record>
   <Record Type="Common.ValueListParameterDisplayOnly">
    <PropertyValue Property="ValueListProperty" String="CountryName"/>
  </Record>
</Collection>

Indicated Smartfield configuration as dropdown and displayBehavior as idAndDescription, but all I get inthe output is Id and instead of description -> again ID!

Has someone had the same problem or has any idea how and what to change?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

EkanshCapgemini
Active Contributor
0 Kudos

Hey,

For others who read it later, here is the solution to this problem.

You need to add the below annotation to the key property which directs it to the description property for value help entity.

sap:text="Ddtext"

I created a tiny helper method to ease it for future so that we pass just value help entity name, entityset name, inout property name and its description property name.

  METHOD set_as_dropdown.

    DATA: lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
          lo_property    TYPE REF TO /iwbep/cl_mgw_odata_property,
          lt_property    TYPE TABLE OF /iwbep/med_external_name,
          lo_annotation  TYPE REF TO /iwbep/if_mgw_odata_annotation,
          lo_entity_set  TYPE REF TO /iwbep/if_mgw_odata_entity_set.

    lo_entity_set = model->get_entity_set( iv_entity_set_name = i_entityset ).
    IF lo_entity_set IS BOUND.
      lo_annotation = lo_entity_set->create_annotation( 'sap' ).
      lo_annotation->add( iv_key = 'semantics' iv_value = 'fixed-values').
    ENDIF.

    lo_entity_type = model->get_entity_type( iv_entity_name = i_entity ).
    IF lo_entity_type IS BOUND.
      "For this property (dropdown value), we define its "Description"
      lo_property ?= lo_entity_type->get_property( i_key_property ).
      lo_annotation = lo_property->/iwbep/if_mgw_odata_annotatabl~create_annotation( 'sap' ).
      lo_annotation->add( iv_key = 'text' iv_value = i_desc_property ).
    ENDIF.

  ENDMETHOD.