SAP / odata-vocabularies

SAP Vocabularies for semantic markup of structured data published via OData (www.odata.org) services.
https://sap.github.io/odata-vocabularies
Apache License 2.0
165 stars 62 forks source link

ConnectedFields annotation #29

Closed crazio closed 4 years ago

crazio commented 4 years ago

Hi,

I've faced an issue while trying to use ConnectedFields annotation. Let's imagine I want to create List Report for Products and for some column I want to see 'Product Number - Product Description' format display. For instance, we can have following CDS annotations:

//...
UI : {

        LineItem : [
            { $Type : 'UI.DataFieldForAnnotation', Target : '@UI.ConnectedFields#ProductNumberDescr' },
            { $Type : 'UI.DataField', Value : weight },
            { $Type : 'UI.DataField', Value : weightUnit }
        ],

        ConnectedFields#ProductNumberDescr : {
            Label : 'Product',
            Template : '{Number}-{Description}',
            Data : {
                Number : { $Type : 'UI.DataField', Value : number },
                Description : { $Type : 'UI.DataField', Value : description }
            }
        },
    },
//...

After compiling, we will get xml markup which looks really similar like in example mentioned in documentation

<Annotation Term="UI.ConnectedFields" Qualifier="ProductNumberDescr">
          <Record Type="UI.ConnectedFieldsType">
            <PropertyValue Property="Data">
              <Record Type="Core.Dictionary">
                <PropertyValue Property="Description">
                  <Record Type="UI.DataField">
                    <PropertyValue Property="Value" Path="description"/>
                  </Record>
                </PropertyValue>
                <PropertyValue Property="Number">
                  <Record Type="UI.DataField">
                    <PropertyValue Property="Value" Path="number"/>
                  </Record>
                </PropertyValue>
              </Record>
            </PropertyValue>
            <PropertyValue Property="Label" String="Product"/>
            <PropertyValue Property="Template" String="{Number}-{Description}"/>
          </Record>
</Annotation>

Anyway it doesn't work: we won't see any field in List. I guess for Data property we should specify array, so corresponding Data property should look something like:

//...
Data : [ { Number : { $Type : 'UI.DataField', Value : number } },
             { Description : { $Type : 'UI.DataField', Value : description } } ]
//...

For both cases cds gives me descriptive error For the 1st case: record type 'Core.Dictionary' doesn't have a property 'Description' record type 'Core.Dictionary' doesn't have a property 'Number' and for the 2nd found collection value, but expected non-collection type Core.Dictionary

Is everything specified correct. I used UI vocabulary as a reference

Thanks in advance

BerSie commented 4 years ago

Hi crazio, if you say that you create a List Report - do you use Fiori Elements or do you use the SmartTable control to create your own List Report? Thanks and best regards, Bernhard

crazio commented 4 years ago

I use Fiori Smart Template. Here is the link for my application

BerSie commented 4 years ago

... and you are using the version for OData v4 apparently. That's great on the one hand side - on the other side it's not officially released (although some basic things are already working. Unfortunately the support of semantically connected fields is not implemented, yet. But it's on the list (there is a backlog item for that). I checked your cds code - if you fine of having a visualization like number(description) or description(number) you may use the Common.Text annotation and in first case in conjunction with the UI.TextArrangement annotation. Would this be an option for you? Semantically it makes definitely sense as the description will be the text for the number, right. Let me know what you think about it. With regards the release of Fiori Elements for OData v4 I would like to point you to a blog post: https://blogs.sap.com/2020/03/17/fiori-elements-floorplans-for-odata-v4-coming-soon/.

crazio commented 4 years ago

Thanks a lot, Bernhard! I will go with your approach