Skip to Content
0

OData Create method with auto incremental ID

May 20, 2017 at 10:07 PM

72

avatar image

I'm trying to perform the OData.create method on my SAPUI5 application. However, when calling the create method from the controller.js I get this error:

The serialized resource has an missing value for member 'ID'

This is the structure of the ID column in the SAP HANA database:

"ID" INTEGER CS_INT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY

When trying to insert through a SQL command in SAP HANA it inserts just fine without specifying the ID.

However, through the application it is not working.

var newGMID = {

GMID: 7653,

COUNTRY_CODE_ID: 34,

CURRENCY_CODE_ID: 344,

IBP_RELEVANCY_CODE_ID: 370,

NETTING_DEFAULT_CODE_ID: 374,

QUADRANT_CODE_ID: 378,

CHANNEL_CODE_ID: 383,

MARKET_DEFAULT_CODE_ID: 386,

TYPE: "SEEDS",

GMID_COUNTRY_STATUS_CODE_ID: 389 };

var oDataModel = this.getView().getModel(); oDataModel.create("/GMID_SHIP_TO_COUNTRY", newGMID,

{

success: function(oData, oResponse)

{ MessageToast.show("GMID successfully inserted into DB"); },

error: function(oData, oResponse)

{ MessageToast.show("Error. GMID not inserted."); }

});

I have an Odata Service set up (version 2) and have no custom code for my .xsodata file.

"BAMDEV"."GMID_SHIP_TO_COUNTRY" as "GMID_SHIP_TO_COUNTRY";

I have tried including the ID in my newGMID object as null, 0, "" but with no luck. It gives me a duplicate key error when trying to insert twice with the same ID. It is therefore not auto-incrementing.

If I specify the ID to a random number and it is not yet in the database, it inserts just fine.

Any help would be much appreciated.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers