Technology Blog Posts by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
daniel_wang09
Product and Topic Expert
Product and Topic Expert
2,106

Hi All,

while developing the custom free-style UI5 app with OData v2, I’m using SAP smart controls to save some development time, and I have some examples to share.

PresentationVariant Annotation

  • Defines the visualizations and sort order for the UI presentation.
  • Visualizations are defined using UI.LineItem annotation.
  • Sort order is based on the given field property in descending order.
  • Note: under my experience, if you use ResponsiveTable type, then the sorter can not be applied by annotation.
<Annotations Target="your_srv.entity_type">
  <Annotation Term="com.sap.vocabularies.UI.v1.PresentationVariant">
    <Record>
      <PropertyValue Property="Visualizations">
        <Collection>
          <AnnotationPath>@UI.LineItem</AnnotationPath>
        </Collection>
      </PropertyValue>
      <PropertyValue Property="SortOrder">
        <Collection>
          <Record Type="Common.SortOrderType">
            <PropertyValue Property="Property" PropertyPath="field1" />
            <PropertyValue Property="Descending" Bool="true"/>
          </Record>
        </Collection>
        <Collection>
          <Record Type="Common.SortOrderType">
            <PropertyValue Property="Property" PropertyPath="field2" />
            <PropertyValue Property="Descending" Bool="true"/>
          </Record>
        </Collection>
      </PropertyValue>
    </Record>
  </Annotation>
</Annotations>

daniel_wang09_0-1761015055565.png

 

FilterRestrictions Annotation:

  • Specifies the filter restrictions for the entity type.
  • Requires filters to be applied and lists properties with filter expression restrictions.
  • In this example, both field1 and field2 are set as mandatory filters, and only a single value is allowed.
<Annotations Target="your_srv.your_srv_Entities/EntitySet">
  <Annotation Term="Org.OData.Capabilities.V1.FilterRestrictions">
    <Record Type="Capabilities.FilterRestrictionsType">
      <PropertyValue Property="RequiresFilter" Bool="true"/>
      <PropertyValue Property="RequiredProperties">
        <Collection>
          <PropertyPath>field1</PropertyPath>
          <PropertyPath>field2</PropertyPath>
        </Collection>
      </PropertyValue>
      <PropertyValue Property="FilterExpressionRestrictions">
        <Collection>
          <Record Type="Capabilities.FilterExpressionRestrictionType">
            <PropertyValue Property="Property" PropertyPath="field1"/>
            <PropertyValue Property="AllowedExpressions" String="SingleValue"/>
          </Record>
          <Record Type="Capabilities.FilterExpressionRestrictionType">
            <PropertyValue Property="Property" PropertyPath="field2"/>
            <PropertyValue Property="AllowedExpressions" String="SingleValue"/>
          </Record>
        </Collection>
      </PropertyValue>
    </Record>
  </Annotation>
</Annotations>

RequiresFilter to set mandatoryRequiresFilter to set mandatory

Single Value only in value helpSingle Value only in value help

 

Common.FieldControl:

  • Hides certain fields or properties based on field control type.
  • Used to hide fields like field1.
<Annotations Target="your_srv.EntityType/field1">
  <Annotation Term="com.sap.vocabularies.Common.v1.FieldControl" EnumMember="com.sap.vocabularies.Common.v1.FieldControlType/Hidden"/>
</Annotations>

daniel_wang09_6-1761015921505.png

You can also use this annotation to field binded Value List.

daniel_wang09_4-1761015605116.png

 

Common.Text and UI.TextArrangement Annotations:

  • Specifies the text arrangement.
  • Defines whether text should be displayed first, last, or only.
  • Example see below value list annotation.
<Annotations Target="your_srv.EntityType/field1">
  <Annotation Term="Common.Text" Path="field1_name">
    <Annotation Term="UI.TextArrangement" EnumMember="UI.TextArrangementType/TextFirst"/></Annotation>
  <Annotation Term="Common.ValueList">
    <Record>
      <PropertyValue Property="Label" String="{i18n&gt;Field1}"/>
      <PropertyValue Property="CollectionPath" String="ZEXAMPLE_VH"/>
      <PropertyValue Bool="true" Property="SearchSupported"/>
      <PropertyValue Property="Parameters">
        <Collection>
          <Record Type="Common.ValueListParameterOut">
            <PropertyValue Property="LocalDataProperty" PropertyPath="field1"/>
            <PropertyValue Property="ValueListProperty" String="ValueList_field1"/>
          </Record>
          <Record Type="Common.ValueListParameterDisplayOnly">
            <PropertyValue Property="ValueListProperty" String="ValueList_field1_name" />
          </Record>
        </Collection>
      </PropertyValue>
    </Record>
  </Annotation>
</Annotations>

daniel_wang09_5-1761015801692.png

 

 UI.HiddenFilter Annotation:

  • Hides certain filters in the mentioned entity in Target attribute.
  • this can be implemented in both your data entity (hide in smartFilters) or value help entity(hide in value help dialog).
<Annotations Target="your_srv.EntityType/field1">
  <Annotation Term="UI.HiddenFilter" Bool="true"/>
</Annotations>

daniel_wang09_7-1761015965872.png

 

You can also find some local annotation examples in this blog by Chandra: https://community.sap.com/t5/technology-blog-posts-by-members/some-of-ui-annotations-local-annotatio... 

I hope my examples are clear and can save some of your development time.

 

Thanks,

Daniel