Skip to Content
avatar image
Former Member

How to insert multiple entries in oModel.create ?

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

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

    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) {
    								});
    								},
    Add comment
    10|10000 characters needed characters exceeded

  • May 13 at 07:05 PM

    google sap gateway batch

    Add comment
    10|10000 characters needed characters exceeded

  • May 14 at 06:06 AM
    Add comment
    10|10000 characters needed characters exceeded