abap-platform-rap-opensap icon indicating copy to clipboard operation
abap-platform-rap-opensap copied to clipboard

@UI.presentationVariant.sortOrder is not working

Open mainakaich opened this issue 2 years ago • 1 comments

In https://github.com/SAP-samples/abap-platform-rap-opensap/blob/main/week2/unit5.md, step 7, the following annotation is used

@UI: { headerInfo: { typeName: 'Travel', typeNamePlural: 'Travels', title: { type: #STANDARD, label: 'Travel', value: 'TravelID' } } , presentationVariant: [{ sortOrder: [{ by: 'TravelID', direction: #DESC }] }] }

But this is giving following HTTP error when I am executing the fiori element preview from service binding.

{"error":{"code":"005056A509B11EE1B9A8FEA8DE87F78E","message":{"lang":"en","value":"Property desc not found in type TravelType"},"innererror":{"transactionid":"B59C0F42C9AF00D0E0064C6C73AFDC9D","timestamp":"20230731132547.3575230","Error_Resolution":{"SAP_Transaction":"For backend administrators: use ADT feed reader "SAP Gateway Error Log" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details","SAP_Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"}}}} --440328ACE08C04162E2AD8A5960092FD0--

The reason for the error is, the URL which is generated is - GET Travel?sap-client=100&$skip=0&$top=20&$orderby=%20desc&$select=TravelId%2cAgencyId%2cAgencyName%2cCustomerId%2cCustomerName%2cBeginDate%2cEndDate%2cBookingFee%2cCurrencyCode%2cTotalPrice%2cDescription%2cTravelStatus%2cTravelUuid&$inlinecount=allpages HTTP/1.1

Here in the orderby=%20desc& is not containing the TravelID as mentioned in the @UI annotation. Could you please check and help me.

mainakaich avatar Jul 31 '23 13:07 mainakaich

I encountered an issue where the field name in the annotation did not match the case of the actual field definition, which is case-sensitive.

Initially, I wrote the following annotation:

presentationVariant: [{ sortOrder: [{ by: 'TravelID', direction: #DESC }] }]

However, in my data model (ZI_TRAVEL), the field was defined as TravelId, not TravelID. Since the field names are case-sensitive, this mismatch caused the error.

The corrected annotation looks like this:

presentationVariant: [{ sortOrder: [{ by: 'TravelId', direction: #DESC }] }]

Here’s the complete and corrected metadata annotation:

@Metadata.layer: #CORE
@ui: {
  headerInfo: { 
    typeName: 'Travel',
    typeNamePlural: 'Travels',
    title: { type: #STANDARD, label: 'Travel', value: 'TravelId' } 
  },
  presentationVariant: [{ 
    sortOrder: [{ by: 'TravelId', direction: #DESC }] 
  }]
}
annotate view ZC_RAP_Travel_### with

This resolved the issue by aligning the field name in the annotation with its actual definition in the data model.

iboabap avatar Dec 30 '24 13:12 iboabap