filterrequestodatasapui5expand

SAPUI5: Odatamodelv2.read with filter cannot read properties of undefined (reading substr)


I have a problem reading data from a model with some filters and expand:

let selectedMaterial =  this.getModel("appSettings").getProperty("/selectedLineItemMaterial");
let selectedSoldToParty = this.getModel("salesDoc").getProperty("/SoldToParty");
this.oSalesContractModel = this.getModel("SalesContract"); 

if (selectedMaterial) {
   var tFilters = [
         new Filter({ path: "to_SalesContract/SoldToParty", operator: FilterOperator.Contains, value1: selectedSoldToParty }),
         new Filter({ path: "Material", operator: FilterOperator.EQ, value1: selectedMaterial }) ];
          

//$filter=substringof(%271001%27,to_SalesOrder/SoldToParty)%20eq%20true&$expand=to_SalesOrder&$inlinecount=allpages&$filter=Material%20eq%20%271%27

          this.oSalesContractModel.read('A_SalesContractItem', {
                  urlParameters: {
                      "$expand": "to_SalesContract", 
                  },
                  filters: tFilters,
                  success: function (oData, oResponse) {
                    debugger;
                    
                    console.log("Data loaded successfully:", oData);
                    console.log(oResponse)
                },
                error: function (oError) {
                  debugger;
                   
                    console.error("Error loading data:", oError);
                }                
            });
          }

I want to do a read request with some filters and expand property (to_SalesOrder is 1:1), on odatamodel v2, however, I am getting the error below: enter image description here

I get the same error if I do the request as a single string: $filter=substringof(%271001%27,to_SalesOrder/SoldToParty)%20eq%20true&$expand=to_SalesOrder&$inlinecount=allpages&$filter=Material%20eq%20%271%27

Has somebody any idea what I am doing wrong here? enter image description here


Solution

  • SOLUTION: I just forgot the "/" in this.oSalesContractModel.read('A_SalesContractItem',...) so it must be this.oSalesContractModel.read('/A_SalesContractItem',...), then it worked