1

I'm using OData services to send data to an SAP system. When I'm doing a

oModel.create({data})

Is there any way to let the server give me as response the ID or field I just created in the database?

Any suggestion is welcome.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Kevine
  • 110
  • 1
  • 1
  • 15

1 Answers1

1

Yes, this is a very common use case.

Model the id as a field of your entity.

Leave the id empty when making the call from the Frontend.

The server fills the id field in the response. In the response, the server may also change or fill any other field of the entity.

in your backend method MYENTITY_CREATE_ENTITY, do something like

io_data_provider->read_entry_data( IMPORTING es_data = ls_myentity ).

"create object in database which fills the field lv_id_from_database

ls_myentity-id = lv_id_from_database.
er_entity = ls_myentity.

Frontend:

oModel.create("/Myentity", 
    oDataCreate, null, false, 
         function(oData, oResponse){
                  //Function for Success
         },
         function(oData, oResponse){
                  //Function for Error
});
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Gerd Castan
  • 6,275
  • 3
  • 44
  • 89