Skip to Content
0

How to determine if the entity is new (created by createEntry

5 days ago

35

avatar image

I am creating a common save routine but I need to take a different action if the entity is an existing entity on the backend or if it is a new entity created by the createEntry. Is there a way to distinguish between these in the oData model? I would think that somewhere it must know so that it can call the backend differently to update or add new.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jamie Cawley
5 days ago
0

If you are using createEntry then the model will handle this for you. All you have to do is just use submitChanges, which will submit new entries as well as edits.

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel

Regards,

Jamie

Show 4 Share
10 |10000 characters needed characters left characters exceeded

Thank you and I understand that submitChanges can handle this. However, I also need to take different actions if the entity is new or one that already exits before I call submitChanges. Something like this:

if (oEntity.isNew()) {this.logNew(entity);}

oModel.submitChanges(...);

Mike

0

You can look at the oRequestQueue which contains anything created by createEntry in the model object.

Regards,

Jamie

0

where is that found. I looked at oData model and found a property called mRequests but this is empty. Do you know where the queue is kept?

Mike

0

Oh sorry, oRequestQueue is not part of the V2 model, you should be able to use getPendingChanges to see the entries. The id will have a different format for the new entries vs the edited ones. You could also look at mDeferredRequests which contains the entire request.

Regards,

Jamie

0