Sap Fiori Add Visual Filter

作者 SAP69e2c50833f1無授權條款收錄於 2026年10月8日更新於 2026年10月8日

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

AI 產生的概覽

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

功能
此技能指導在 OData V4 的 SAP Fiori Elements 篩選列或值說明對話框中,新增以圖表為基礎的視覺化篩選器(長條圖或折線圖)。它會先收集實體、維度欄位、量值欄位、彙總方式和圖表類型等必要輸入。接著提供 CDS 註解、ABAP RAP 中繼資料擴充註解、前端 annotation.xml 內容以及資訊清單設定。它也列出 CAP 與 RAP 專案的測試命令與常見錯誤。
適用情境
當 SAP Fiori Elements 應用程式需要在篩選列或值說明對話框中加入以圖表為基礎的篩選器時使用。適用於使用 OData V4 且需要設定彙總與圖表註解的 CAP 或 ABAP RAP 專案。不適用於沒有視覺化篩選器的一般值說明對話框。
執行需求
需要一個以 OData V4 為基礎的 SAP Fiori Elements 專案,使用 CAP 或 ABAP RAP,並包含 CDS、ABAP 中繼資料擴充、annotation.xml 和 manifest.json 檔案。測試部分引用 npm run watch- 、cds watch、npm run start-mock 和 npm start 等 npm 指令碼,並提到 ADT MCP 與 Fiori MCP 伺服器作為選用輔助。此技能不隨附指令碼,僅為說明文件。

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]

Manifest configuration (MANDATORY)

refer to the "Manifest Configuration" section below.


ABAP RAP Implementation (4 Steps)

CRITICAL: NEVER EDIT metadata.xml - IT IS READ-ONLY!

1. Backend CDS (MANDATORY) - Enable Aggregation Support

abap
@OData.applySupportedForAggregation: #FULLdefine root view entity ZC_ENTITY  provider contract TRANSACTIONAL_QUERY  as projection on ZR_ENTITY{  @Aggregation.default: #SUM  Amount;  Category;}

2. Backend Metadata Extension (MANDATORY) - Add Chart, PresentationVariant, SelectionField Annotations

abap
@UI.chart: [{  qualifier: 'visualFilter',  chartType: #BAR,  dimensions: ['Category'],  measures: ['Amount']}]@UI.presentationVariant: [{  qualifier: 'visualFilter',  visualizations: [{    type: #AS_CHART,    qualifier: 'visualFilter'  }]}]
annotate view ZC_ENTITY with{  @UI.selectionField: [{ position: 10 }]  Category;
  @EndUserText.label: 'Amount'  Amount;}

3. Frontend (annotation.xml)

Chart Annotation:

xml
<Annotations Target="EntityType/Category"><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></Annotations>

4. Manifest configuration (MANDATORY)

refer to the "Manifest Configuration" section below.


Manifest Configuration

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

CRITICAL: Manifest Configuration Structure

NEVER nest visualFilter inside a settings property!


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:

  • Aggregation + measures defined in CDS
  • Uses DynamicMeasures
  • Aggregation and chart defined in same place

RAP:

  • Aggregation defined in backend CDS only
  • Uses Measures (not DynamicMeasures)
  • Metadata is read-only

Common Mistakes

  • Backend Changes are not activated.
  • Qualifier mismatch between Chart, ValueList, PresentationVariant, and manifest
  • Wrong path in manifest (use full vocabulary path)
  • Missing SelectionField annotation
  • Non-numeric measure field
  • Missing compact visual layout configuration in manifest

RAP:

  • Missing backend aggregation support
  • Using DynamicMeasures instead of Measures
  • Adding Common.ValueList in backend instead of frontend (ValueList MUST be in frontend annotation.xml)
  • Adding UI annotations directly in CDS projection view instead of metadata extension
  • Trying to use @Consumption.valueHelpDefinition for visual filters (that's for value help dialogs, not visual filters)

Best Practices

  • Always activate backend changes in ADT MCP before testing
  • Use 1 dimension + 1 measure per visual filter
  • Prefer Bar charts for better readability
  • Keep qualifier names consistent across all annotations
  • Test with different data volumes
  • Always include layout: "CompactVisual" and initialLayout: "Visual" in manifest

RAP Specific:

  • ALWAYS use ADT MCP to modify backend files when available
  • Chart + PresentationVariant → Backend metadata extension (.ddlx.acds)
  • Common.ValueList → Frontend annotation.xml (CANNOT be in backend)

References

來源與署名

來源:SAP/open-ux-tools位於packages/fiori-mcp-server/skills/sap-fiori-add-visual-filter提交69e2c50

授權條款: 無授權條款

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

檢舉或申請下架