Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
venkatachala_ck
Active Participant

Hi,

Introduction:

  In UI5 we can send multiple records using batch operation. Here i have a application which can send data to the back-end using array of objects and i also gone through other blogs in SCN which describes about batch operations but they used static objects for sending data. In this application you can able to send more number of records using dynamic object creation by converting data into JSON format.

Description:

  The application contains some input fields and table for storing data for performing operations like add, change and delete.After completion of data operations if you want send multiple records to the back-end using batch operations,first you have convert data into JSON format.

Below code snippet describes how to get table data and pushing into an array.

var items = [];// intializing an array

var aTableData = oTable.getModel().getData();// getting table data

for (i = 0; i < oTableData.length; i++) {

items.push( {

"ItemKey": aTableData[i].Item,

"ItempartGrp": oTableData[i].itemcodegroup,

  "ItempartCod": oTableData[i].itemcode,

  "ItemdefectGrp": oTableData[i].problemcodegroup,

  "ItemdefectCod": oTableData[i].problemcode,

  "ItemdefectShtxt": oTableData[i].problemdescription,

  "CauseGrp": oTableData[i].causegroup,

  "CauseCod": oTableData[i].causecode,

  "CauseShtxt": oSel[i].causedescription,

  });

}

// oEntry is the main object to send data using batch operation.

//Pushing table data with some other values(i,e NotifType,FunctionLoc).

  var oEntry = {

  "NotifType": xtitle,

  "Qmnum": " ",

  "NotifShorttxt": shrttext,

  "FunctionLoc": FuncLocation,

  "Equipment": Equipmentno,

"NavNotifItems": JSON.parse(JSON.stringify(items)),

  //  converting data into json format

// string type will converted into json object by parsing it.

};

  var sServiceUrl = "http://your url SRV/"; // ODATA URL

  var oDModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);

//creating batch operation

  oDModel.create("/url", oEntry, null, function(oData, oResponse)

  {

  //function openDialog() {

  var oDialog1 = new sap.m.Dialog();

  oDialog1.setTitle("Success Message");

  var ovalue = new sap.m.Text({

  text: "Notification" + oData.Qmnum + " is Created"

  });

  var oVmain = new sap.m.FlexBox("Dialog", {

  items: [ovalue]

  });

  oDialog1.addContent(oVmain);

  oDialog1.addButton(new sap.m.Button({

  text: "OK",

  press: function() {

  oDialog1.close();

  }

  }));

  oDialog1.open();

  // };

  console.log(oResponse);

                sap.ui.getCore().byId("detailPage").rerender();

  },

  function(err) {

     //Error Callback

   jQuery.sap.require("sap.m.MessageBox");

      sap.m.MessageBox.show((JSON.parse(err.response.body).error.message.value));

    }

table screen shot for performing data operations

NOTE :  Upto my knowledge this is the best way to adding  table data to the back-end using batch operation by converting data into JSON format.

             if any doubts regarding this hit a comment and if any better methods  please let me know.

Thanks and Regards

Venkatachala C.K

24 Comments
Labels in this area