Sap Fiori Add Visual Filter

作者 cline26378461e978無授權條款34 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫2 個月前更新

Add visual filters (chart-based) to SAP Fiori Elements filter bar/value help using CAP or ABAP RAP.

AI 產生的概覽

使用 CAP 或 ABAP RAP 為 SAP Fiori Elements 篩選列與值說明新增以圖表為基礎的視覺化篩選器。

功能
引導代理在 OData V4 的 SAP Fiori Elements 篩選列或值說明對話框中,新增以圖表(長條圖或折線圖)為基礎的視覺化篩選器。內容涵蓋 CAP 的 CDS 註解與 ABAP RAP 的註解 XML,包括彙總設定、圖表、呈現變式、值清單與選取欄位註解,以及必要的 manifest 設定。同時列出測試指令與常見錯誤。
適用情境
當 Fiori Elements 應用程式需要針對以數值量值彙總的維度欄位新增以圖表為基礎的篩選器時使用。適用於採用 OData V4 的 CAP 或 ABAP RAP 專案。使用前需先確認實體、維度欄位、量值欄位、彙總方式與圖表類型。
執行需求
此技能未附帶指令碼,僅為說明文件。它假定已有以 OData V4 為基礎的 SAP Fiori Elements 專案,使用 CAP(CDS 註解、cds/npm watch)或 ABAP RAP(後端 CDS 與 metadata.xml),並需要 npm 來執行所列的執行指令。文中提到 Fiori MCP 伺服器為選用,用於重新整理 RAP 中繼資料。

SAP Fiori Visual Filter

Purpose

Add chart-based filters (Bar/Line) to filter bar or value help dialog (OData V4).


MANDATORY: Gather Required Inputs First

STOP and ASK the user for ALL of these inputs if ANY are missing from the prompt:

  1. Entity - Which entity to add the visual filter to
  2. Dimension field - The field to filter by (e.g., Category, Status, Destination)
  3. Measure field - The numeric field to aggregate (e.g., Amount, TotalPrice, ReservationPrice)
  4. Aggregation method - How to aggregate: sum, avg, min, or max
  5. Chart type - Bar or Line (recommend Bar as default)

DO NOT proceed with implementation until all inputs are confirmed.


CAP Implementation

Enable Aggregation (MANDATORY)

cds
@Aggregation.ApplySupported: {  Transformations: ['aggregate','groupby'],  AggregatableProperties: [{ Property: Amount }],  GroupableProperties: [Category]}

Aggregated Property (Measure)

cds
Analytics.AggregatedProperty #Amount_sum : {  $Type: 'Analytics.AggregatedPropertyType',  Name: 'Amount_sum',  AggregatableProperty: Amount,  AggregationMethod: 'sum'}

Chart Annotation

cds
UI.Chart #visualFilter : {  ChartType: #Bar,  Dimensions: [Category],  DynamicMeasures: ['@Analytics.AggregatedProperty#Amount_sum']}

✅ Uses DynamicMeasures

PresentationVariant

cds
UI.PresentationVariant #visualFilter: {  Visualizations: ['@UI.Chart#visualFilter']}

ValueList (on Dimension Field)

cds
Category @Common.ValueList #visualFilter: {  $Type: 'Common.ValueListType',  CollectionPath: 'EntityName',  Parameters: [    { $Type: 'Common.ValueListParameterInOut', LocalDataProperty: Category, ValueListProperty: 'Category' }  ],  PresentationVariantQualifier: 'visualFilter'}

SelectionFields

cds
UI.SelectionFields: [Category]

ABAP RAP Implementation

  • Aggregation.ApplySupported and Aggregation.CustomAggregate annotations must be available in metadata.xml (RAP). If not, below backend configuration is required.

Backend CDS (MANDATORY)

abap
@OData.applySupportedForAggregation: #FULLdefine root view entity ZC_ENTITY  provider contract analytical_query  as projection on ZI_ENTITY{  key EntityID,
  @Aggregation.default: #SUM  Amount,
  Category}

Chart Annotation

xml
<Annotation Term="UI.Chart" Qualifier="visualFilter">  <Record Type="UI.ChartDefinitionType">    <PropertyValue Property="ChartType" EnumMember="UI.ChartType/Bar"/>    <PropertyValue Property="Dimensions">      <Collection>        <PropertyPath>Category</PropertyPath>      </Collection>    </PropertyValue>    <PropertyValue Property="Measures">      <Collection>        <PropertyPath>Amount</PropertyPath>      </Collection>    </PropertyValue>  </Record></Annotation>

✅ Uses Measures (not DynamicMeasures)
❌ Metadata is read-only

PresentationVariant Annotation

xml
<Annotation Term="UI.PresentationVariant" Qualifier="visualFilter">  <Record Type="UI.PresentationVariantType">    <PropertyValue Property="Visualizations">      <Collection>        <AnnotationPath>@UI.Chart#visualFilter</AnnotationPath>      </Collection>    </PropertyValue>  </Record></Annotation>

ValueList Annotation

xml
<Annotation Term="Common.ValueList" Qualifier="visualFilter">  <Record Type="Common.ValueListType">    <PropertyValue Property="CollectionPath" String="EntityName"/>    <PropertyValue Property="PresentationVariantQualifier" String="visualFilter"/>    <PropertyValue Property="Parameters">      <Collection>        <Record Type="Common.ValueListParameterInOut">          <PropertyValue Property="LocalDataProperty" PropertyPath="Category"/>          <PropertyValue Property="ValueListProperty" String="Category"/>        </Record>      </Collection>    </PropertyValue>  </Record></Annotation>

SelectionFields Annotation

xml
<Annotation Term="UI.SelectionFields">  <Collection>    <PropertyPath>Category</PropertyPath>  </Collection></Annotation>

Manifest Configuration (REQUIRED)

json
"@com.sap.vocabularies.UI.v1.SelectionFields": {  "layout": "CompactVisual",  "initialLayout": "Visual",  "filterFields": {    "Category": {      "visualFilter": {        "valueList": "com.sap.vocabularies.Common.v1.ValueList#visualFilter"      }    }  }}

✅ Connects filter field to visual filter chart
✅ Sets initial layout to visual mode


Testing

CAP Projects

bash
npm run watch-<app-name>  # e.g., npm run watch-manage-travel# or use generic watch script if availablecds watch

RAP Projects

bash
npm run start-mock # Needs metadata refresh
npm start          # No refresh needed - fetches metadata from live backend at runtime
  • Consult fiori mcp server if available on how to refresh metadata for sap/cloud systems in case of RAP

Key Differences

  • CAP: DynamicMeasures + AggregatedProperty defined in CDS
  • RAP: Measures + @Aggregation.default in backend CDS only
  • CAP: Aggregation and chart defined in same place
  • RAP: Metadata is read-only, must be configured in backend CDS.
  • Qualifier: Must use same qualifier (#visualFilter) across Chart, ValueList, and manifest

Common Mistakes

  • Missing backend aggregation setup
  • Qualifier mismatch between Chart, ValueList, PresentationVariant, and manifest
  • Wrong path in manifest (use full vocabulary path)
  • RAP projects using DynamicMeasures instead of Measures
  • Forgetting PresentationVariantQualifier in ValueList
  • Missing SelectionFields annotation

Best Practices

  • Use Bar chart (most common and recommended)
  • Limit to 3–5 visual filters per filter bar
  • Always configure backend aggregation first
  • Use consistent qualifiers throughout
  • Test with real data to verify aggregation works correctly

來源與署名

來源:cline/skills位於skills/sap-fiori-add-visual-filter提交2637846

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架