📊sap-fiori-add-visual-filter
- プラグイン
- sap-fiori-mcp-server
- 引数
- field name (e.g., Category, Status)
- ソース
- GitHub で見る ↗
説明
視覚的なフィルター(チャートベース)を、CAP または ABAP RAP を使用して SAP Fiori Elements のフィルターバー/値ヘルプに追加します。
原文を表示
Add visual filters (chart-based) to SAP Fiori Elements filter bar/value help using CAP or ABAP RAP.
ユースケース
- ✓SAP Fiori Elementsのフィルターバーに追加したいとき
- ✓値ヘルプに視覚的フィルターを追加するとき
- ✓CAP または ABAP RAP を使用するとき
本文(日本語訳)
SAP Fiori ビジュアルフィルター
目的
フィルターバーまたは値ヘルプダイアログ(OData V4)に、チャートベースのフィルター(Bar / Line) を追加します。
必須: 実装前に必要な入力情報を収集すること
以下の情報がプロンプトに一つでも不足している場合は、必ず一時停止してユーザーに確認してください:
- エンティティ - ビジュアルフィルターを追加する対象エンティティ
- ディメンションフィールド - フィルタリングに使用するフィールド(例: Category, Status, Destination)
- メジャーフィールド - 集計対象となる数値フィールド(例: Amount, TotalPrice, ReservationPrice)
- 集計メソッド - 集計方法: sum / avg / min / max のいずれか
- チャートタイプ - Bar または Line(デフォルトは Bar を推奨)
すべての入力情報が確認できるまで、実装を進めないでください。
CAP 実装
集計の有効化(必須)
@Aggregation.ApplySupported: {
Transformations: ['aggregate','groupby'],
AggregatableProperties: [{ Property: Amount }],
GroupableProperties: [Category]
}
集計プロパティ(メジャー)
Analytics.AggregatedProperty #Amount_sum : {
$Type: 'Analytics.AggregatedPropertyType',
Name: 'Amount_sum',
AggregatableProperty: Amount,
AggregationMethod: 'sum'
}
チャートアノテーション
UI.Chart #visualFilter : {
ChartType: #Bar,
Dimensions: [Category],
DynamicMeasures: ['@Analytics.AggregatedProperty#Amount_sum']
}
✅ DynamicMeasures を使用
PresentationVariant
UI.PresentationVariant #visualFilter: {
Visualizations: ['@UI.Chart#visualFilter']
}
ValueList(ディメンションフィールドに設定)
Category @Common.ValueList #visualFilter: {
$Type: 'Common.ValueListType',
CollectionPath: 'EntityName',
Parameters: [
{ $Type: 'Common.ValueListParameterInOut', LocalDataProperty: Category, ValueListProperty: 'Category' }
],
PresentationVariantQualifier: 'visualFilter'
}
SelectionFields
UI.SelectionFields: [Category]
Manifest 設定(必須)
下記「Manifest 設定」セクションを参照してください。
ABAP RAP 実装(4ステップ)
重要: metadata.xml は絶対に編集しないこと — 読み取り専用です!
1. バックエンド CDS(必須)— 集計サポートの有効化
@OData.applySupportedForAggregation: #FULL
define root view entity ZC_ENTITY
provider contract TRANSACTIONAL_QUERY
as projection on ZR_ENTITY
{
@Aggregation.default: #SUM
Amount;
Category;
}
2. バックエンド メタデータ拡張(必須)— Chart / PresentationVariant / SelectionField アノテーションの追加
@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. フロントエンド(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 設定(必須)
下記「Manifest 設定」セクションを参照してください。
Manifest 設定
"@com.sap.vocabularies.UI.v1.SelectionFields": {
"layout": "CompactVisual",
"initialLayout": "Visual",
"filterFields": {
"Category": {
"visualFilter": {
"valueList": "com.sap.vocabularies.Common.v1.ValueList#visualFilter"
}
}
}
}
重要: Manifest 設定の構造について
settings プロパティの内部に visualFilter をネストしないでください!
テスト
CAP プロジェクト
npm run watch-<app-name> # 例: npm run watch-manage-travel
# または汎用 watch スクリプトが利用可能な場合
cds watch
RAP プロジェクト
npm run start-mock # メタデータのリフレッシュが必要
npm start # リフレッシュ不要 — 実行時にライブバックエンドからメタデータを取得
- SAP / クラウドシステムにおける RAP のメタデータリフレッシュ方法については、利用可能であれば Fiori MCP サーバーを参照してください。
CAP と RAP の主な違い
CAP:
- 集計とメジャーは CDS 内で定義
- DynamicMeasures を使用
- 集計とチャートを同じ場所で定義
RAP:
- 集計はバックエンド CDS のみで定義
- Measures を使用(DynamicMeasures は使用しない)
- メタデータは読み取り専用
よくある間違い
- バックエンドの変更がアクティベートされていない
- Chart / ValueList / PresentationVariant / Manifest 間での Qualifier の不一致
- Manifest 内のパスが誤っている(フルボキャブラリーパスを使用すること)
- SelectionField アノテーションの設定漏れ
- メジャーフィールドに非数値型を使用している
- Manifest に CompactVisual レイアウト設定が含まれていない
RAP 固有:
- バックエンドの集計サポートが設定されていない
- Measures の代わりに DynamicMeasures を使用している
- Common.ValueList をフロントエンドではなくバックエンドに追加している (ValueList は必ずフロントエンドの annotation.xml に記述すること)
- UI アノテーションをメタデータ拡張ではなく CDS プロジェクションビューに直接記述している
- ビジュアルフィルターに
@Consumption.valueHelpDefinitionを使用しようとしている (これは値ヘルプダイアログ用であり、ビジュアルフィルターには使用不可)
ベストプラクティス
- テスト前に必ず ADT MCP でバックエンドの変更をアクティベートする
- ビジュアルフィルターごとにディメンション 1つ・メジャー 1つを使用する
- 視認性向上のため Bar チャートを優先する
- すべてのアノテーション間で Qualifier 名を統一する
- 異なるデータ量でテストを行う
- Manifest には必ず
layout: "CompactVisual"およびinitialLayout: "Visual"を含める
RAP 固有:
- バックエンドファイルの変更には、利用可能な場合は必ず ADT MCP を使用する
- Chart + PresentationVariant → バックエンド メタデータ拡張(
.ddlx.acds) - Common.ValueList → フロントエンド annotation.xml(バックエンドには記述不可)
参考リンク
- ABAP RAP 集計サポート: https://help.sap.com/docs/abap-cloud/abap-rap/projection-view
原文(English)を表示
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:
- Entity - Which entity to add the visual filter to
- Dimension field - The field to filter by (e.g., Category, Status, Destination)
- Measure field - The numeric field to aggregate (e.g., Amount, TotalPrice, ReservationPrice)
- Aggregation method - How to aggregate: sum, avg, min, or max
- Chart type - Bar or Line (recommend Bar as default)
DO NOT proceed with implementation until all inputs are confirmed.
CAP Implementation
Enable Aggregation (MANDATORY)
@Aggregation.ApplySupported: {
Transformations: ['aggregate','groupby'],
AggregatableProperties: [{ Property: Amount }],
GroupableProperties: [Category]
}
Aggregated Property (Measure)
Analytics.AggregatedProperty #Amount_sum : {
$Type: 'Analytics.AggregatedPropertyType',
Name: 'Amount_sum',
AggregatableProperty: Amount,
AggregationMethod: 'sum'
}
Chart Annotation
UI.Chart #visualFilter : {
ChartType: #Bar,
Dimensions: [Category],
DynamicMeasures: ['@Analytics.AggregatedProperty#Amount_sum']
}
✅ Uses DynamicMeasures
PresentationVariant
UI.PresentationVariant #visualFilter: {
Visualizations: ['@UI.Chart#visualFilter']
}
ValueList (on Dimension Field)
Category @Common.ValueList #visualFilter: {
$Type: 'Common.ValueListType',
CollectionPath: 'EntityName',
Parameters: [
{ $Type: 'Common.ValueListParameterInOut', LocalDataProperty: Category, ValueListProperty: 'Category' }
],
PresentationVariantQualifier: 'visualFilter'
}
SelectionFields
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
@OData.applySupportedForAggregation: #FULL
define 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
@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:
<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
"@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
npm run watch-<app-name> # e.g., npm run watch-manage-travel
# or use generic watch script if available
cds watch
RAP Projects
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
- ABAP RAP Aggregation support: https://help.sap.com/docs/abap-cloud/abap-rap/projection-view
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。