The name of the EntitySet. It can start with a "/" (slash)
modelName?
string
No
undefined
The name of the OData V2 model which can be found on the manifest.json file. Leave this parameter undefined if the name of the OData model = "" (empty string)
Tip for TypeScript
The ODataCreateCL<EntityT> is a generic class that can be initialized with a type containing the properties of the EntitySet specified as a parameter in the class constructor.
The EntityT type is used as the type for the data parameter of the setData(data: EntityT) method and as the return type for the getData(): EntityT method.
Additionally, the EntityT type is utilized as the return type for the create(): Promise<EntityT> method, which is employed to facilitate the POST request through the sap.ui.model.odata.v2.ODataModel.
importControllerfrom"sap/ui/core/mvc/Controller";importODataCreateCLfrom"ui5/antares/odata/v2/ODataCreateCL";// Import the class/** * @namespace your.apps.namespace */exportdefaultclassYourControllerextendsController{publiconInit(){}publicasynconCreateProduct(){// Initialize without a typeconstodata=newODataCreateCL(this,"Products");}publicasynconCreateCategory(){// Initialize with a typeconstodata=newODataCreateCL<ICategory>(this,"Categories");}publicasynconCreateCustomer(){// Initialize with a model nameconstodata=newODataCreateCL(this,"Customers","myODataModelName");}}interfaceICategory{ID:string;name?:string;}
sap.ui.define(["sap/ui/core/mvc/Controller","ui5/antares/odata/v2/ODataCreateCL"// Import the class],/** * @param {typeof sap.ui.core.mvc.Controller} Controller */function(Controller,ODataCreateCL){"use strict";returnController.extend("your.apps.namespace.YourController",{onInit:function(){},onCreateProduct:asyncfunction(){// Initializeconstodata=newODataCreateCL(this,"Products");},onCreateCategory:asyncfunction(){// Initialize with a model nameconstodata=newODataCreateCL(this,"Categories","myODataModelName");}});});
Set Data
To define the data that will be transmitted via the POST HTTP request body, the setData() method can be utilized.
Tip
It is also possible to set the data for the navigation properties (deep create).
Parameter
Type
Mandatory
Description
data
EntityT
Yes
The data that will be sent via the POST HTTP request body
Returns
Description
EntityT
Returns the value that was set using setData() method. Default value is undefined
importControllerfrom"sap/ui/core/mvc/Controller";importODataCreateCLfrom"ui5/antares/odata/v2/ODataCreateCL";// Import the class/** * @namespace your.apps.namespace */exportdefaultclassYourControllerextendsController{publiconInit(){}publicasynconCreateProduct(){// Initialize with a typeconstodata=newODataCreateCL<IProducts>(this,"Products");// set the http bodyodata.setData({ID:"b2f0013e-418f-42aa-9a24-3770fe17ce18",name:"Product Name",description:"Description",brand:"Brand",price:999,currency:"EUR",quantityInStock:15,categoryID:"eb7783a6-f30f-4f7d-b85c-f211eea54568",supplierID:"7734d25f-0d1e-4ab4-b8a8-cd201f29fd2f"});}}interfaceIProducts{ID:string;name:string;description:string;brand:string;price:number;currency:string;quantityInStock:number;categoryID:string;supplierID:string;}
sap.ui.define(["sap/ui/core/mvc/Controller","ui5/antares/odata/v2/ODataCreateCL"// Import the class],/** * @param {typeof sap.ui.core.mvc.Controller} Controller */function(Controller,ODataCreateCL){"use strict";returnController.extend("your.apps.namespace.YourController",{onInit:function(){},onCreateProduct:asyncfunction(){// Initializeconstodata=newODataCreateCL(this,"Products");// set the http bodyodata.setData({ID:"b2f0013e-418f-42aa-9a24-3770fe17ce18",name:"Product Name",description:"Description",brand:"Brand",price:999,currency:"EUR",quantityInStock:15,categoryID:"eb7783a6-f30f-4f7d-b85c-f211eea54568",supplierID:"7734d25f-0d1e-4ab4-b8a8-cd201f29fd2f"});}});});
Create Request
To send a POST (Create) request through the OData V2 model, you can use the create() method.
Attention
It is a prerequisite that data be set using the setData() method before calling the create() method.
Info
The create() method runs asynchronously and can be awaited.
If the request is successful, the create() method will return the data of the newly created entity.
Warning
In the event of a failed POST request, the OData Create class will generate an error message. To ensure the error is identified and addressed, it is recommended to call the create() method within a try-catch block.
Error Type
In the event of a failed POST request, the object generated by the class can contain the properties outlined below.
importControllerfrom"sap/ui/core/mvc/Controller";importODataCreateCLfrom"ui5/antares/odata/v2/ODataCreateCL";// Import the classimport{IError}from"ui5/antares/types/common";// Import the error typeimportMessageBoxfrom"sap/m/MessageBox";/** * @namespace your.apps.namespace */exportdefaultclassYourControllerextendsController{publiconInit(){}publicasynconCreateProduct(){// Initialize with a typeconstodata=newODataCreateCL<IProducts>(this,"Products");// set the http bodyodata.setData({ID:"b2f0013e-418f-42aa-9a24-3770fe17ce18",name:"Product Name",description:"Description",brand:"Brand",price:999,currency:"EUR",quantityInStock:15,categoryID:"eb7783a6-f30f-4f7d-b85c-f211eea54568",supplierID:"7734d25f-0d1e-4ab4-b8a8-cd201f29fd2f"});try{// send the http request and get the resultconstresult=awaitodata.create();MessageBox.information(result.ID+" was created.");}catch(error){// catch the errorMessageBox.error((errorasIError).message||"Request failed");}}}interfaceIProducts{ID:string;name:string;description:string;brand:string;price:number;currency:string;quantityInStock:number;categoryID:string;supplierID:string;}
sap.ui.define(["sap/ui/core/mvc/Controller","ui5/antares/odata/v2/ODataCreateCL",// Import the class"sap/m/MessageBox"],/** * @param {typeof sap.ui.core.mvc.Controller} Controller */function(Controller,ODataCreateCL,MessageBox){"use strict";returnController.extend("your.apps.namespace.YourController",{onInit:function(){},onCreateProduct:asyncfunction(){// Initializeconstodata=newODataCreateCL(this,"Products");// set the http bodyodata.setData({ID:"b2f0013e-418f-42aa-9a24-3770fe17ce18",name:"Product Name",description:"Description",brand:"Brand",price:999,currency:"EUR",quantityInStock:15,categoryID:"eb7783a6-f30f-4f7d-b85c-f211eea54568",supplierID:"7734d25f-0d1e-4ab4-b8a8-cd201f29fd2f"});try{// send the http request and get the resultconstresult=awaitodata.create();MessageBox.information(result.ID+" was created.");}catch(error){// catch the errorMessageBox.error(error.message||"Request failed");}}});});
URL Parameters
Prior to sending the POST request with the create() method, it is possible to set the URL parameters using the setUrlParameters() method.
Parameter
Type
Mandatory
Description
urlParameters
Record<string, string>
Yes
The URL parameters of the POST request
Returns
Description
Record<string, string> | undefined
Returns the value that was set using setUrlParameters() method. Default value is undefined
importControllerfrom"sap/ui/core/mvc/Controller";importODataCreateCLfrom"ui5/antares/odata/v2/ODataCreateCL";// Import the class/** * @namespace your.apps.namespace */exportdefaultclassYourControllerextendsController{publiconInit(){}publicasynconCreateProduct(){// Initialize with a typeconstodata=newODataCreateCL<IProducts>(this,"Products");// set the url parametersodata.setUrlParameters({"$expand":"toProductLocations"});}}interfaceIProducts{ID:string;name:string;description:string;brand:string;price:number;currency:string;quantityInStock:number;categoryID:string;supplierID:string;}
importControllerfrom"sap/ui/core/mvc/Controller";importODataCreateCLfrom"ui5/antares/odata/v2/ODataCreateCL";// Import the class/** * @namespace your.apps.namespace */exportdefaultclassYourControllerextendsController{publiconInit(){}publicasynconCreateProduct(){// Initialize with a typeconstodata=newODataCreateCL<IProducts>(this,"Products");// deactivate the auto model refreshodata.setRefreshAfterChange(false);}}interfaceIProducts{ID:string;name:string;description:string;brand:string;price:number;currency:string;quantityInStock:number;categoryID:string;supplierID:string;}
1 2 3 4 5 6 7 8 910111213141516171819202122232425
sap.ui.define(["sap/ui/core/mvc/Controller","ui5/antares/odata/v2/ODataCreateCL"// Import the class],/** * @param {typeof sap.ui.core.mvc.Controller} Controller */function(Controller,ODataCreateCL){"use strict";returnController.extend("your.apps.namespace.YourController",{onInit:function(){},onCreateProduct:asyncfunction(){// Initializeconstodata=newODataCreateCL(this,"Products");// deactivate the auto model refreshodata.setRefreshAfterChange(false);}});});
Additional Response Info
The create() method returns the data of the successfully created entity. However, you may require further information such as the status code and headers.
Once the create() function has been completed, the getResponse() method can be utilized to obtain further details.
importControllerfrom"sap/ui/core/mvc/Controller";importODataCreateCLfrom"ui5/antares/odata/v2/ODataCreateCL";// Import the classimport{IError}from"ui5/antares/types/common";// Import the error typeimportMessageBoxfrom"sap/m/MessageBox";/** * @namespace your.apps.namespace */exportdefaultclassYourControllerextendsController{publiconInit(){}publicasynconCreateProduct(){// Initialize with a typeconstodata=newODataCreateCL<IProducts>(this,"Products");// set the http bodyodata.setData({ID:"b2f0013e-418f-42aa-9a24-3770fe17ce18",name:"Product Name",description:"Description",brand:"Brand",price:999,currency:"EUR",quantityInStock:15,categoryID:"eb7783a6-f30f-4f7d-b85c-f211eea54568",supplierID:"7734d25f-0d1e-4ab4-b8a8-cd201f29fd2f"});try{// send the http request and get the resultconstresult=awaitodata.create();MessageBox.information(result.ID+" was created.");// get the additional response infoconstresponse=odata.getResponse();if(response){console.log("Status Code: "+response.statusCode);}}catch(error){// catch the errorMessageBox.error((errorasIError).message||"Request failed");}}}interfaceIProducts{ID:string;name:string;description:string;brand:string;price:number;currency:string;quantityInStock:number;categoryID:string;supplierID:string;}
sap.ui.define(["sap/ui/core/mvc/Controller","ui5/antares/odata/v2/ODataCreateCL",// Import the class"sap/m/MessageBox"],/** * @param {typeof sap.ui.core.mvc.Controller} Controller */function(Controller,ODataCreateCL,MessageBox){"use strict";returnController.extend("your.apps.namespace.YourController",{onInit:function(){},onCreateProduct:asyncfunction(){// Initializeconstodata=newODataCreateCL(this,"Products");// set the http bodyodata.setData({ID:"b2f0013e-418f-42aa-9a24-3770fe17ce18",name:"Product Name",description:"Description",brand:"Brand",price:999,currency:"EUR",quantityInStock:15,categoryID:"eb7783a6-f30f-4f7d-b85c-f211eea54568",supplierID:"7734d25f-0d1e-4ab4-b8a8-cd201f29fd2f"});try{// send the http request and get the resultconstresult=awaitodata.create();MessageBox.information(result.ID+" was created.");// get the additional response infoconstresponse=odata.getResponse();if(response){console.log("Status Code: "+response.statusCode);}}catch(error){// catch the errorMessageBox.error(error.message||"Request failed");}}});});
Create Entry
To create a transient entity context which can be bound to a form or a dialog, the createEntry() method can be utilized.
Tip
If you wish to create the context with the initial values, the setData() method can be utilized.