cancel
Showing results for 
Search instead for 
Did you mean: 

How to do deep insert in SAPUI5?

former_member184238
Participant
0 Kudos

Hi,

I am doing CRUD operations in SAPUI5 using Gateway service. In that I have to send data through Json for deep insert.I can create using Rest Client in firefox. But in my program I have to send the same data from Form. But I am in confusion how to send the data through Json for deep Insert.

Could you please send me a useful links regarding this .

Thanks&Regards

Sridevi

Accepted Solutions (0)

Answers (5)

Answers (5)

raeijpe
Contributor
0 Kudos

In SAP Gateway OData, the deep insert is the opposite of the reading a joined entityset ($expand).

For this, there must be an association between the two entitysets.

So by reading the dataset in json format with for example the path

{

  path: "/Products",

  parameters: {expand: "Category"}

}

Will return you the right structure. And this structure, you can use in the create.

You also must be aware that you define the model for JSON format:

sap.ui.model.odata.ODataModel(sServiceUrl, bJSON?, sUser?, sPassword?, mHeaders?, bTokenHandling?, bWithCredentials?, bLoadMetadataAsync?, annotationURI?, loadAnnotationsJoined?)


- bJSON must be true or set the header to accept JSON

And you need a CSRF token, before calling the create method.

You can implement the refreshSecurityToken method of OData model.

rlindner81
Employee
Employee
0 Kudos

Here is a simple example of the JSON format that is required...

var sId = Math.random().toString(36).substring(7);
var nCount = 1;

var oData = {
    NotificationNumber : sId,
    NotificationItem : [ {
        ItemNumber : (nCount++).toString(),
        NotificationNumber : sId,
    }, {
        ItemNumber : (nCount++).toString(),
        NotificationNumber : sId,
    }, {
        ItemNumber : (nCount++).toString(),
        NotificationNumber : sId,
    }, ],
};

var fnSuccess = function(oData, oResponse) {
    alert("Success....");
};
var fnError = function(oError) {
    alert("Error creating \"/NotificationHeaders\" on Gateway Service.");
    alert("Response was\n" + oError.response.body);
};

oDataModel.create("/NotificationHeaders", oData, null, fnSuccess, fnError);
Former Member
0 Kudos

You know that I am facing some troubles with NW Gateway about a deep insert but for one association:

This is my JSON:

{

  FirstName : "Juan",

  LastName : "Duran"

  Spouse : {

    FirstName : "Maria",

    LastName : "Duque"

  }

}

And I want those two objects to be inserted in a "ZPEOPLE" table. How should I do that? (NW Gateway)

A 'Person' entity type should be defined as PersonId, FirstName, LastName, SpouseId (The one-to-one relationship between two 'Person' entities)

Thank you in advance

Former Member
0 Kudos

Hi Sridevi,

Please see this link : http://scn.sap.com/community/developer-center/front-end/blog/2012/11/18/gateway-batch-calls-from-sap...

You can find, through the example of this blog, some samples data on how to "format" your json to "deep insert".

Take a look at how this blog fill the Contact_Status attribute.

Cheers

Former Member
0 Kudos

Hi Sridevi,

Get the data from the form and send the data to server via loadData method

Refer the below link:

https://sapui5.netweaver.ondemand.com/sdk/#docs/api/symbols/sap.ui.model.json.JSONModel.html#loadDat...


Regards,

Ajain

former_member293602
Active Participant
0 Kudos

Hi Sridevi,

for general information on the´topic of data binding in SAPUI5 you can check here: https://sapui5.netweaver.ondemand.com/sdk/#docs/guide/DataBinding.html. For more specifics on oData and write support: https://sapui5.netweaver.ondemand.com/sdk/#docs/guide/ODataWrite.html.

Regards, Frank