cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Smart Table with annotation.xml

francesco_zambon21
Discoverer
0 Likes
464

 

Hello,

I created a freestyle application configured with an OData V2 service. After generating the project, I added an annotations.xml file to define the columns for my entity type. Then, I added a SmartTable controller bound to my entity.

However, the columns are not being displayed in the SmartTable.
Could you please help me understand what might be missing or incorrectly configured?

Thank you.

Main.view.xml

<mvc:View
    controllerName="dummy3.controller.Main"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns="sap.m"
    xmlns:smartTable="sap.ui.comp.smarttable"
>
    <Page
        id="page"
        title="{i18n>title}"
    >
        <smartTable:SmartTable
            id="idSalesOrderSmartTable"
            entitySet="ZC_SALESORDER_HEADER"
            header="Sales Order"
            enableAutoBinding="true"
        />
    </Page>
</mvc:View>

Main.controller.ts

import SmartTable from "sap/ui/comp/smarttable/SmartTable";
import Controller from "sap/ui/core/mvc/Controller";
import ODataModel from "sap/ui/model/odata/v2/ODataModel";

/**
 * @namespace dummy3.controller
 */
export default class Main extends Controller {

    /*eslint-disable @typescript-eslint/no-empty-function*/
    public onInit(): void {

        const serviceUri = this.getOwnerComponent()!.getManifestEntry("/sap.app/dataSources").mainService.uri;
        console.log("serviceUri: " + serviceUri);
        const model = new ODataModel(serviceUri);

        this.getView()!.setModel(model);
    }
}

annotation0.xml

<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
    <edmx:Reference Uri="/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_COMMON',Version='0001',SAP__Origin='LOCAL')/$value">
        <edmx:Include Namespace="com.sap.vocabularies.Common.v1" Alias="Common"/>
    </edmx:Reference>
    <edmx:Reference Uri="/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_UI',Version='0001',SAP__Origin='LOCAL')/$value">
        <edmx:Include Namespace="com.sap.vocabularies.UI.v1" Alias="UI"/>
    </edmx:Reference>
    <edmx:Reference Uri="/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Vocabularies(TechnicalName='%2FIWBEP%2FVOC_COMMUNICATION',Version='0001',SAP__Origin='LOCAL')/$value">
        <edmx:Include Namespace="com.sap.vocabularies.Communication.v1" Alias="Communication"/>
    </edmx:Reference>
    <edmx:Reference Uri="/sap/opu/odata/sap/ZUI_CUSTOMERS_SRV_V2/$metadata">
        <edmx:Include Namespace="cds_zc_customers_srv" Alias="SAP"/>
    </edmx:Reference>
    <edmx:DataServices>
        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="local1">

            <Annotations Target="cds_zc_customers_srv.ZC_SALESORDER_HEADERType">
                <Annotation Term="UI.LineItem">
                    <Collection>
                        <Record Type="UI.DataField">
                            <PropertyValue Property="Value" Path="OrderNumber"  />
                        </Record>
                    </Collection>
                </Annotation>
                
            </Annotations>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

manifest.json

{
    "_version": "1.76.0",
    "sap.app": {
        "id": "dummy3",
        "type": "application",
        "i18n": "i18n/i18n.properties",
        "applicationVersion": {
            "version": "0.0.1"
        },
        "title": "{{appTitle}}",
        "description": "{{appDescription}}",
        "resources": "resources.json",
        "sourceTemplate": {
            "id": "@sap/generator-fiori:basic",
            "version": "1.19.0",
            "toolsId": "48310874-b0e7-4597-8f03-42bef0d4e584"
        },
        "dataSources": {
            "ZUI_CUSTOMERS_SRV_V2_VAN": {
                "uri": "/sap/opu/odata/IWFND/CATALOGSERVICE;v=2/Annotations(TechnicalName='ZUI_CUSTOMERS_SRV_V2_VAN',Version='0001')/$value/",
                "type": "ODataAnnotation",
                "settings": {
                    "localUri": "localService/mainService/ZUI_CUSTOMERS_SRV_V2_VAN.xml"
                }
            },
            "mainService": {
                "uri": "/sap/opu/odata/sap/ZUI_CUSTOMERS_SRV_V2/",
                "type": "OData",
                "settings": {
                    "annotations": [
                        "ZUI_CUSTOMERS_SRV_V2_VAN",
                        "annotation0"
                    ],
                    "localUri": "localService/mainService/metadata.xml",
                    "odataVersion": "2.0"
                }
            },
            "annotation0": {
                "type": "ODataAnnotation",
                "uri": "annotations/annotation0.xml",
                "settings": {
                    "localUri": "annotations/annotation0.xml"
                }
            }
        }
    },
    "sap.ui": {
        "technology": "UI5",
        "icons": {
            "icon": "",
            "favIcon": "",
            "phone": "",
            "phone@2": "",
            "tablet": "",
            "tablet@2": ""
        },
        "deviceTypes": {
            "desktop": true,
            "tablet": true,
            "phone": true
        }
    },
    "sap.ui5": {
        "flexEnabled": true,
        "dependencies": {
            "minUI5Version": "1.141.3",
            "libs": {
                "sap.m": {},
                "sap.ui.core": {}
            }
        },
        "contentDensities": {
            "compact": true,
            "cozy": true
        },
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "settings": {
                    "bundleName": "dummy3.i18n.i18n"
                }
            },
            "": {
                "dataSource": "mainService",
                "preload": true,
                "settings": {}
            }
        },
        "resources": {
            "css": [
                {
                    "uri": "css/style.css"
                }
            ]
        },
        "routing": {
            "config": {
                "routerClass": "sap.m.routing.Router",
                "controlAggregation": "pages",
                "controlId": "app",
                "transition": "slide",
                "type": "View",
                "viewType": "XML",
                "path": "dummy3.view",
                "async": true,
                "viewPath": "dummy3.view"
            },
            "routes": [
                {
                    "name": "RouteMain",
                    "pattern": ":?query:",
                    "target": [
                        "TargetMain"
                    ]
                }
            ],
            "targets": {
                "TargetMain": {
                    "id": "Main",
                    "name": "Main"
                }
            }
        },
        "rootView": {
            "viewName": "dummy3.view.App",
            "type": "XML",
            "id": "App",
            "async": true
        }
    }
}

 

Accepted Solutions (0)

Answers (1)

Answers (1)

francesco_zambon21
Discoverer
0 Likes

Hello,

I resolved the issue. I needed to pass my annotations.xml file during the model creation.

        const serviceUri = this.getOwnerComponent()!.getManifestEntry("/sap.app/dataSources").mainService.uri;
        console.log("serviceUri: " + serviceUri);

        const localAnnotationUrl = sap.ui.require.toUrl("dummy3/annotations/annotation0.xml");
        console.log("localAnnoUrl: " + localAnnotationUrl);

        const model = new ODataModel(serviceUri, {
            annotationURI: localAnnotationUrl
        });