Skip to Content

sending data to the back-end using JSON format



  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.


  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.addButton(new sap.m.Button({

  text: “OK”,

  press: function() {




  // };




  function(err) {

     //Error Callback“sap.m.MessageBox”);;


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

You must be Logged on to comment or reply to a post.
  • Hi Venkatachala,

    Nice try, But I have some query.

    1. Creating Batch operation - SAPUI5-Odata Model has batch operation property to send the series of jobs into database. But here you are using for loop with oDATA call for oTableData.length number of time, is it any specific reason?

    Gateway Batch Calls from SAPUI5

    JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

    2. Correct me if I am wrong, If oDATAModel calls occurs oTableData.length number of times, It might give a performance issue and reduce the database health.

    Assume my table has 10,000 records, will this code calls 10,000 times to trigger oDATAModel class?


    Karthik A

    • Hi Karthik,

      Sorry i forgot to close for loop.(i corrected now)

      actually i'm pushing all data to an array(items) and i'm putting array in to an object(oEntry).

      Here oDATAModel call occurs only one time using batch operation and i'm taking oTableData.length to push all table items at time.

      thanks for correcting me

  • Hi Venkatachala,

    Your code is returning an error for me:Error while parsing an XML stream

    How did you set your Entity in the gateway so that one parameter can receive a table?

    The problem is when I call the service with the parameter: "NavNotifItems": JSON.parse(JSON.stringify(items)).


          • No, perfectly fine. The problem was when I tried passing integers and the code couldn't parse them to string for some reason.

            However here's my working code for future reference:



              "Qmnum": '11',

              "Kunum": '22'



            var oEntry = {

               "Qmnum": '1',

               "Kunum": '2',

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


            oModel.create("/oDeepInsertSet", oEntry, null, function(oData, oResponse)




              function(err) {

              // Error Callback




              this.setModel(oJSONModel, 'theModel');

  • Nice blog:)

    But i have another doubt..

    I have created a matrix layout to get user inputs and trying to manually show that inputs getting added to table (just to display) on screen by adding those inputs,,and then i want to post  the table data to back end array using batch operation..

    Can u help me on how to add user inputs to my table on screen???

    • Please create a new Discussion marked as a Question.  The Comments section of a Blog (or Document) is not the right vehicle for asking questions as the results are not easily searchable.  Once your issue is solved, a Discussion with the solution (and marked with Correct Answer) makes the results visible to others experiencing a similar problem.  If a blog or document is related, put in a link.

      NOTE: Getting the link is easy enough for both the author and Blog.  Simply MouseOver the item, Right Click, and select Copy Shortcut.  Paste it into your Discussion.  You can also click on the url after pasting.  Click on the A to expand the options and select T (on the right) to Auto-Title the url.

      Thanks, Mike (Moderator)

      SAP Technology RIG

  • Hi venkatachala,

    Helpful post but for me this code ran into some issues.

    Where you're pushing table data with some other values(i,e NotifType,FunctionLoc) there are variables used like xTitle for NotifType, FuncLoc for Function location and so on. Are these mandatory fields to be declared? also if it is then what do we put in these fields?

    For e.g. what do I put in the variable xTitle that is assigning value to NotifType?

    Because I am not having the right data for this variable I am getting the following error-

    Property 'NotifType' is invalid
    Your help would be highly appreciated.


    • Looks like these fields are not available in my gateway service. Can you please tell me how is it related from on the SAP Gateway side? What do we look for and implement in SEGW? if there is anything related to this.



    • Hello Chandan,

      This is just a sample data in JSON format for posting, and the same payload is not mandatory for all the scenarios. If i know your scenario may be i can help you with that.






      • Hi Venkat,

        Thanks for your response.

        In my case now that I have made my own oEntry payload with just one field for e.g. "Jobs"

        When I execute the code I get the error that the property "Jobs" is invalid.

        something like this-

        "message":{"lang":"en","value":"Property 'Jobs' is invalid"}

        I feel there should be something maintained at the backend side? isn't it? at the gateway maybe?

        What is NavNotifItems in your backend code (in SAP)?




  • Hi David, I hope you got the answer to Property ‘NotifType’ is invalid. 

    I am also getting the same error message. either Venkadachalam or any helper can help me as I am new in OData? My requirement is not a deep insert to push master and details data. I just wanted to push simple only one table rows. thx. - Swami