-1

I'm new to SAPUI5 and I'm having problems...

When I use a read function to get a value from an OData service, I'm trying to use another read function inside the success function, using a filter with the value that I obtained from the first read.

Is this even possible?

Up to now, it just seems like it reads successfully, but then it doesn't execute the next read.

var filters = new Array();
var first_Filter = new sap.ui.model.Filter({
  path: "userId",
  operator: sap.ui.model.FilterOperator.EQ,
  value1: userId
});
filters.push(first_Filter);
this.getOwnerComponent().getModel().read("/users", {
  filters: la_filters,
  success: function(oData, response) {
    var data = oData.results[0];
    var jobid = data.jobId;
    var filters2 = new Array();
    var second_Filter2 = new sap.ui.model.Filter({
      path: "idJob",
      operator: sap.ui.model.FilterOperator.EQ,
      value1: jobid
    });
    filters2.push(second_Filter2);
    this.getOwnerComponent().getModel().read("/jobs", {
      filters: la_filters2,
      success: function(oData2) { 
        // read odata ,get value and pass it on...
      }
    });
  }
});
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
jota
  • 25
  • 6

1 Answers1

0

the this inside the second read is not the correct one.

save a reference to this (outside the first read) like var that = this; and use it to make the second read like

that.getOwnerComponent().getModel().read("/jobs", {
  filters: la_filters2,
  success: function(oData2) { 
    // read odata ,get value and pass it on...
  }
});
StErMi
  • 5,389
  • 5
  • 48
  • 71