cancel
Showing results for 
Search instead for 
Did you mean: 

UI5 - Create a new object with OData v4 model

ssimsekler
Active Contributor

Hi

Another mystery yet to be resolved and the posts I found does not really give proper solution.

We have OData v4 services implemented with CAP and we now want to implement freestyle UI5 applications that will use the OData v4 services.

The UI5 SDK documentation assumes there is a list binding and the "Creating an Entity" section only refers to the sap.ui.model.odata.v4.ODataListBinding#create method.

Our application does not start with a list, e.g. the user can click on a button upon which a dialog appears to receive input data and upon clicking Save button it saves the new object data.

In this case, how can we create a transient entity without a "list" that can then be saved with submitBatch?

Girish_Kumar_Gu
Participant
0 Kudos

Hi Serdar

Were you able to find a solution for the issue? I am in a similar situation. The documentation doesn't help.

Thanks

arunmbarec
Participant
0 Kudos

Hi Thomas,

After i execute the create method, the request for the post is triggered by the framework. How do i prevent this being automatically executed and send the post request only when the save button is triggered. I am going through the two links you have specified in your response but i still don't get the clarity. Do you have a code sample on what properties to set during binding.create()

Regards,
Arun K

moshenaveh
Community Manager
Community Manager
0 Kudos

arun.krishnamoorthy1988

Hello, While we're happy that you've come to SAP Community to get an answer to your question, you posted your question as an answer in an old thread. I've converted your answer to a comment, but even so -- posting in older threads is not the best way to get guidance. If you're looking for help, you should ask a new question: https://answers.sap.com/questions/ask.html. Here are some tips to help you craft an effective question for our community: https://community.sap.com/resources/questions-and-answers, https://developers.sap.com/tutorials/community-qa.html, https://groups.community.sap.com/t5/welcome-corner-discussions/advice-from-sap-champions-questions-a.... I encourage you to follow this guidance, as I'd really like to see you get a solution to your problem. I hope you find this advice useful!

View Entire Topic
thomas_chadzelek
Participant

Hello Serdar!

Thanks for using OData V4! Turns out that sap.ui.model.odata.v4.ODataListBinding#create is indeed the right method, even if you do not show a table UI. As discussed in Accessing Data in Controller Code, "A list binding is obtained either with sap.ui.model.odata.v4.ODataModel#bindList, or by getting an existing list binding bound to a control." Once you have a list binding, there is no need to read data at all before creating a new entity! You can even create this new entity when you open the dialog, get back a v4.Context immediately, and use it as a binding context for the dialog!

Best regards,

Thomas

former_member183924
Active Participant
0 Kudos

Hi thomas.chadzelek ,

I think what you've described is best shown in the following sample of the UI5 documentation. However, in our case we want to create the new entry, when the user clicks 'OK'. We want to use a close button to just close the dialog. I currently don't see the way how to do it right, as we don't want to introduce a new entry by just clicking on the plus sign in the table toolbar.

Thanks,
-Steffen

thomas_chadzelek
Participant

Hello steffen ,

please note that you can easily create a transient context which only lives on the client-side. You can control when the actual POST is send to the server. This transient context is useful for the dialog, I would assume, because it can receive the needed user input and provide automatic type determination and even value help, all based on metadata. You can cancel this transient context and never send the POST if the user cancels the dialog (see also Creating an Entity). Or you submit the corresponding batch group (see Batch Control) in case OK is clicked. In other words: "create the new entry, when the user clicks 'OK'" (from a server perspective) is not the same as creating the new entry on the client much earlier.

Best regards,

Thomas