I am currently working with SAPUI5 and developing a extension for the Web Client using the OData Model V4 for data retrieval. However, I am having trouble concerning data binding of a child collection. The datastructure I want to access (which partially works, except for the collection) looks as follows:
{
"Code": "5",
"OBJ_CUST_ADDRCollection": [
{
"Code": "5",
"U_Address": "Construction site",
"U_Street": "Sample Street 20",
"U_City": "New York",
"U_ZipCode": "1234",
"U_CntctName": "John Doe"
}
//This array usually contains multiple entries which have the same schema as the one above.
]
}
My model’s configuration looks as follows:
export const bpModel: ODataModel = new ODataModel({
serviceUrl: `/b1s/v2/`,
synchronizationMode: "None",
operationMode: "Server",
autoExpandSelect: true,
earlyRequests: true,
groupProperties : {
UpdateGroup : {"submit" : "API"}
},
updateGroupId : updateGroupId
});
To retrieve a specific entity, I have used an element binding to bind the bpModel to my view (the key is ‘5’ in this instance):
view.bindElement({
path: `/OBJECT_CUSTOMER('${routingParams.customerObjCode}')`,
model: bpModelName
});
I am using a fragment (for better readability) in my view, which contains the data binding to the collection “OBJ_CUST_ADDRCollection”:
<core:FragmentDefinition
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core">
<VBox width="100%">
<Title text="{i18n>objectAddresses}" class="sapUiSmallMarginBottom"/>
<Table id="objAddresses"
mode="MultiSelect"
class="sapUiSmallMarginBottom"
items="{
path: 'OBJ_CUST_ADDRCollection',
model: 'BP'
}"
sticky="HeaderToolbar,InfoToolbar,ColumnHeaders">
<headerToolbar>
<OverflowToolbar>
<ToolbarSpacer/>
<Button icon="sap-icon://add" press="addAddress"/>
<Button icon="sap-icon://delete" press="deleteAddresses"/>
<Button icon="sap-icon://action-settings" press="changeObjAddressSettings"/>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column>
<Text text="{i18n>objectAddressesID}"/>
</Column>
<Column>
<Text text="{i18n>objectAddressesStreetPOBox}"/>
</Column>
<Column>
<Text text="{i18n>objectAddressesLocation}"/>
</Column>
<Column>
<Text text="{i18n>objectAddressesZipCode}"/>
</Column>
<Column>
<Text text="{i18n>objectAddressesCntctAtLoc}"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{BP>U_Address}" />
<Text text="{BP>U_Street}" />
<Text text="{BP>U_City}" />
<Text text="{BP>U_ZipCode}" />
<Text text="{BP>U_CntctName}" />
</cells>
</ColumnListItem>
</items>
</Table>
</VBox>
</core:FragmentDefinition>
But whenever this fragment (and the corresponding view) is loaded, I encounter the error “Failed to enhance query options for auto-$expand/$select as the child binding has query options, but its path ‘OBJ_CUST_ADDRCollection’ points to a structural property – {“$select”:[“U_Address”,”U_Street”,”U_City”,”U_ZipCode”,”U_CntctName”]} sap.ui.model.odata.v4.lib._Helper”. When checking and manually testing the actual GET request sent by the OData model, I can see that the query parameter $select is used, which caused the request to fail. When I omitted this parameter (in my tests with Insomnia) the request worked.
How do I resolve this error?
At this point I have tried multiple things:
- Setting “autoExpandSelect” to false. This caused the issue to disappear and the collection’s contents were displayed correctly. Yet, this isn’t a solution to me, as I intend to use a deep create later on and “autoExpandSelect: true” is required for this.
- Changing the items aggregation slightly, by adding a “parameters” object containing $select: [ ] and $$ownRequest: true. The only thing this changed for me was, that my batch-request contained another request for the collection itself. The issue concerning $select still persists though.
- Using a Service Layer Extension written in JavaScript. This option gave me a bit more freedom concerning the design of the endpoint, but I wasn’t able to access it with batch-requests. I had to set the groupId to $direct and autoExpandSelect to false for data to be displayed. This did work in the end, but also isn’t ideal. Firstly, the performance seems to be far worse when using a custom endpoint. Secondly, deep create still won’t work due to autoExpandSelect being set to false.
angryBird is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.