Skip to Content
0

How to insert multiple entries in oModel.create ?

May 13 at 04:35 PM

81

avatar image
Former Member

Hi Guy's,

I have a dialog box if i select multipull vendor for a product those records should be insert in hana db . for that i wrote below code it is inserting first record only but success msg coming twice.

	handleClose: function(oEvent) {		
	var vendors = oEvent.getParameters("ven").selectedItems ;
	for (var i = 0; i < vendors.length; i++) {
        var item = vendors[i];
        var oModel = this.getView().getModel();
        var oEntry = {};
   oEntry.PRODUCTID  = PRODUCTID;
   oEntry.VENDOR_NO =  item.getDescription() ;
   oEntry.VENDOR_NAME = item.getTitle();
   oEntry.PRICE     = "0";
   oEntry.STATUS    = "X" ;
   oModel.create("/ADDVENDOR", oEntry, {
	success: function(oEvt){
		
	},
	error: function(oError) {
									if (oError.responseText.split("<MSG_TYPE>")[1].split("")[0] === "S") {
										MessageBox.success("Vendor Add Successfully ");
									} else {
										MessageBox.error("Vendor already exist for Product");
      					
								}
	}
   });   

    }
				},
capture.jpg (16.3 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member May 14 at 11:14 AM
0

Finally i got it

// Globally declared 	
	var oModel, dep, sempid, sUrl, aDataModel, batchChanges = [];
			var oConfig = {
			json: true
			};
// In onInit function
	onInit: function() {
							sUrl = this.getOwnerComponent().getModel().sServiceUrl;
							aDataModel = new sap.ui.model.odata.ODataModel(sUrl, oConfig);


// Mainlogic 
	handleClose: function(oEvent) {
							var vendors = oEvent.getParameters("ven").selectedItems;
							for (var i = 0; i < vendors.length; i++) {
								var item = vendors[i];
								var newData = {
									PRODUCTID: PRODUCTID,
									VENDOR_NO: item.getDescription(),
									VENDOR_NAME: item.getTitle(),
									PRICE: "0",
									STATUS: "X"
								}; //push object to array   
								var batchChanges = [];
								batchChanges.push(aDataModel.createBatchOperation("/ADDVENDOR", "POST", newData));
								aDataModel.addBatchChangeOperations(batchChanges);
							};
							aDataModel.submitBatch(function(data) {
                             	var  a = data.__batchResponses[0].response.body.split("MSG_TYPE")[1].split(":")[1] ;
                               if (a.split("")[1] === "I") {
                               		MessageBox.error("Vendor already exist for Product");
                               }else{ 	MessageBox.success("Vendor Add Successfully ");
                               }
							},
								function(oError) {
								});
								},
Share
10 |10000 characters needed characters left characters exceeded
Jun Wu May 13 at 07:05 PM
0

google sap gateway batch

Share
10 |10000 characters needed characters left characters exceeded
sivakumar M May 14 at 06:06 AM
0
Share
10 |10000 characters needed characters left characters exceeded