Skip to Content

SAPUI5: Annotation - Smartfield with Search Help

Hi Experts,

I've created a smartfield with a searchhelp.

I used an annotation like this:

(in the method define of the ...MPC_EXT)

super->define( ).
    DATA: lo_ann_target TYPE REF TO /iwbep/if_mgw_vocan_ann_target.
    DATA: lo_annotation TYPE REF TO /iwbep/if_mgw_vocan_annotation.
    DATA: lo_collection TYPE REF TO /iwbep/if_mgw_vocan_collection.
    DATA: lo_function   TYPE REF TO /iwbep/if_mgw_vocan_function.
    DATA: lo_fun_param  TYPE REF TO /iwbep/if_mgw_vocan_fun_param.
    DATA: lo_property   TYPE REF TO /iwbep/if_mgw_vocan_property.
    DATA: lo_record     TYPE REF TO /iwbep/if_mgw_vocan_record.
    DATA: lo_simp_value TYPE REF TO /iwbep/if_mgw_vocan_simple_val.
    DATA: lo_url        TYPE REF TO /iwbep/if_mgw_vocan_url.
    DATA: lo_label_elem TYPE REF TO /iwbep/if_mgw_vocan_label_elem.
    DATA: lo_reference  TYPE REF TO /iwbep/if_mgw_vocan_reference.
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_CORE' iv_vocab_version = '0001' ).
    lo_reference->create_include( iv_namespace = 'Org.OData.Core.V1' ).
    lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = '/IWBEP/VOC_COMMON' iv_vocab_version = '0001' ).
    lo_reference->create_include( iv_namespace = 'com.sap.vocabularies.Common.v1' ).
    lo_ann_target = vocab_anno_model->create_annotations_target( 'Product/ProductType' ).
    lo_ann_target->set_namespace_qualifier( 'ZCRM_BUT000_SRV' ).
    lo_annotation = lo_ann_target->create_annotation( iv_term = 'com.sap.vocabularies.Common.v1.ValueList' ).
    lo_record = lo_annotation->create_record( ).
    lo_property = lo_record->create_property( iv_property_name = 'Label' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_string( 'Producttype' ).
    lo_property = lo_record->create_property( iv_property_name = 'CollectionPath' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_string( 'VH_ProductTypeSet' ).
    lo_property = lo_record->create_property( iv_property_name = 'CollectionRoot' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_string( 'ZCRM_BUT000_SRV' ).
    lo_property = lo_record->create_property( iv_property_name = 'SearchSupported' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_boolean( 'X' ).
    lo_property = lo_record->create_property( iv_property_name = 'Parameters' ).
    lo_collection = lo_property->create_collection( ).
    lo_record = lo_collection->create_record( iv_record_type = 'com.sap.vocabularies.Common.v1.ValueListParameterOut' ).
    lo_property = lo_record->create_property( iv_property_name = 'LocalDataProperty' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_property_path( 'ProductType' ). " field of entity "ProductSet"
    lo_property = lo_record->create_property( iv_property_name = 'ValueListProperty' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_property_path( 'KEY' ). " field of entity "VH_ProductTypeSet"
    lo_record = lo_collection->create_record( iv_record_type = 'com.sap.vocabularies.Common.v1.ValueListParameterDisplayOnly' ).
    lo_property = lo_record->create_property( iv_property_name = 'ValueListProperty' ).
    lo_simp_value = lo_property->create_simple_value( ).
    lo_simp_value->set_property_path( 'VALUE' ). " field of entity "VH_ProductTypeSet"

the metadata file looks like this:

<EntityType Name="VH_ProductType" sap:content-version="1">"); vertical-align: bottom; height: 10px;"><Key>
<PropertyRef Name="KEY"/>
</Key>
<Property Name="KEY" Type="Edm.String" Nullable="false" MaxLength="2" sap:label="Product Type" sap:creatable="false" sap:updatable="false"/>
<Property Name="VALUE" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Product Type Descr." sap:creatable="false" sap:updatable="false"/></EntityType>
"); vertical-align: bottom; height: 10px;"><EntityType Name="Product" sap:content-version="1">"); vertical-align: bottom; height: 10px;"><Key>
<PropertyRef Name="ProductGuid"/>
</Key>
<Property Name="ProductGuid" Type="Edm.Guid" Nullable="false" sap:label="Product GUID" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="ProductId" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Product ID"/>
<Property Name="ProductType" Type="Edm.String" Nullable="false" MaxLength="2" sap:label="Product Type"/>
<Property Name="Config" Type="Edm.String" Nullable="false" MaxLength="1" sap:label="Configurable"/>
<Property Name="Xnosearch" Type="Edm.String" Nullable="false" MaxLength="1" sap:label="Product Is Not Relevant for Search Help"/>
<Property Name="ObjectFamily" Type="Edm.String" Nullable="false" MaxLength="4" sap:label="Object Family"/>
<Property Name="BatchDedicated" Type="Edm.String" Nullable="false" MaxLength="1" sap:label="Batch Class"/>
<Property Name="CompetitorProd" Type="Edm.String" Nullable="false" MaxLength="1" sap:label="Competitor Product"/>
<Property Name="ValidFrom" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Valid From"/>
<Property Name="ValidTo" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Valid To"/>
<Property Name="Upname" Type="Edm.String" Nullable="false" MaxLength="12" sap:label="Changed By"/>
<Property Name="Histex" Type="Edm.String" Nullable="false" MaxLength="1" sap:label="History Exists"/>
<Property Name="Logsys" Type="Edm.String" Nullable="false" MaxLength="10" sap:label="Logical System"/></EntityType>
"); vertical-align: bottom; height: 10px;"><EntityContainer Name="ZCRM_BUT000_SRV_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx"><EntitySet Name="BUT000Set" EntityType="ZCRM_BUT000_SRV.BUT000" sap:searchable="true" sap:content-version="1"/>
<EntitySet Name="VH_ProductTypeSet" EntityType="ZCRM_BUT000_SRV.VH_ProductType" sap:searchable="true" sap:content-version="1"/>
<EntitySet Name="ProductSet" EntityType="ZCRM_BUT000_SRV.Product" sap:searchable="true" sap:content-version="1"/>
</EntityContainer>
"); vertical-align: bottom; height: 10px;"><Annotations xmlns="http://docs.oasis-open.org/odata/ns/edm" Target="ZCRM_BUT000_SRV.Product/ProductType">"); vertical-align: bottom; height: 10px;"><Annotation Term="com.sap.vocabularies.Common.v1.ValueList">"); vertical-align: bottom; height: 10px;"><Record>
<PropertyValue Property="Label" String="Producttype"/>
<PropertyValue Property="CollectionPath" String="VH_ProductTypeSet"/>
<PropertyValue Property="CollectionRoot" String="ZCRM_BUT000_SRV"/>
<PropertyValue Property="SearchSupported" Bool="true"/>"); vertical-align: bottom; height: 10px;"><PropertyValue Property="Parameters">"); vertical-align: bottom; height: 10px;"><Collection>
"); vertical-align: bottom; height: 10px;"><Record Type="com.sap.vocabularies.Common.v1.ValueListParameterOut"><PropertyValue Property="LocalDataProperty" PropertyPath="ProductType"/>
<PropertyValue Property="ValueListProperty" PropertyPath="KEY"/>
</Record>
"); vertical-align: bottom; height: 10px;"><Record Type="com.sap.vocabularies.Common.v1.ValueListParameterDisplayOnly"><PropertyValue Property="ValueListProperty" PropertyPath="VALUE"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Annotation>
</Annotations> 

The search-icon is shown:

and the searchhelp appears:

but, the resultlist is empty.

when I click on search, no odata call is executed...

however, when I execute the REST statement for the Value Help for producttype in a browser, I get results:

KR

clipboard01.png (5.0 kB)
clipboard02.png (21.7 kB)
untitled.png (58.5 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Apr 08, 2017 at 08:03 PM

    Found the problem:

    lo_property = lo_record->create_property( iv_property_name ='ValueListProperty').
        lo_simp_value = lo_property->create_simple_value().
        lo_simp_value->set_property_path('KEY')." field of entity "VH_ProductTypeSet"
        lo_record = lo_collection->create_record( iv_record_type ='com.sap.vocabularies.Common.v1.ValueListParameterDisplayOnly').
        lo_property = lo_record->create_property( iv_property_name ='ValueListProperty').
        lo_simp_value = lo_property->create_simple_value().
        lo_simp_value->set_property_path('VALUE')." field of entity "VH_ProductTypeSet"

    must be

    lo_property = lo_record->create_property( iv_property_name ='ValueListProperty').
        lo_simp_value = lo_property->create_simple_value().
        lo_simp_value->set_string('KEY')." field of entity "VH_ProductTypeSet"
        lo_record = lo_collection->create_record( iv_record_type ='com.sap.vocabularies.Common.v1.ValueListParameterDisplayOnly').
        lo_property = lo_record->create_property( iv_property_name ='ValueListProperty').
        lo_simp_value = lo_property->create_simple_value().
        lo_simp_value->set_string('VALUE')." field of entity "VH_ProductTypeSet"
    lo_simp_value->set_string('KEY').

    and

    lo_simp_value->set_string('VALUE').
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 12 at 12:52 AM

    Thank you for posting the solution!

    Add comment
    10|10000 characters needed characters exceeded