0

i have a read operation on an OData Set in which i pass the key. If the key is a string all works fine, but now we switched from String as key datatype to guid as data type and the read call doesn't work anymore. I receive always BAD Request 400.

Here the solution with the String parameter, which works.

var oModel = this.getView().getModel();
var someKey = "Key 1";
  oModel.read("/SomeSet('" + someKey + "')", {
    urlParameters: {"$expand":"SomeItemToExpand"},
    success: function (oData, oResponse) {
      sap.m.MessageToast.show("Read successfulf");              
    },
    error: function (onError) {
      sap.m.MessageBox.error("Error reading");
    }
});

How to pass a guid? I tried:

oModel.read("/SomeSet(guid'" + someKey + "')"

but dows not work.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Francesco Iannazzo
  • 596
  • 2
  • 11
  • 31
  • Does this answer your question? [How to Create Entity Path Dynamically in UI5?](https://stackoverflow.com/questions/46954621/how-to-create-entity-path-dynamically-in-ui5) – Boghyon Hoffmann Jul 12 '21 at 16:20

1 Answers1

1

I finally figured it out the best way pass a guid is:

oModel.read("/SomeSet(SomeKey=guid\'" + someKey + "\')", {

SomeKey= is the key name and this part is optional.

Francesco Iannazzo
  • 596
  • 2
  • 11
  • 31
  • 3
    You should try to use createKey instead. If that key ever changes of type, your app logic still works, e.g.: `oModel.read(oModel.createKey("SomeSet", { SomeKey: someKey }))` – jpenninkhof Jun 10 '16 at 13:14