Hello experts,
I am trying to create a dataset in a draft scenario using as universal an approach as possible.
Unfortunately, I did not find anything more detailed in the documentation.
My goal is:
I have a binding (either sap.ui.model.odata.v4.ODataListBinding or sap.ui.model.odata.v2.ODataListBinding) and I want to create a dataset here directly (not as draft).
But the service itself is enabled as draft (again universal CAP/RAP/V4/V2).
I currently have a PR in my Repo to try this out see here.
The positive is, I can go directly over the binding and create a draft:
draft.create(payload)
But here only a draft is created, and not an enabled record.
As a next step I want to activate this draft.
Currently I have different approaches here.
For V2 I was able to use the sap.ui.generic.app.transaction.DraftController. Using it is pretty straight forward, only checking if draft is possible at all was a bit tricky.
this._draftController.activateDraftEntity(element, true)
For V4 I unfortunately didn't find any direct instructions and the DraftController didn't work. It was a combination of doc (see here) and standard code investigation.
See this implementation here
const operationName = this._getActionName(element, "ActivationAction");
if (operationName) {
const operation = element.getModel().bindContext(`${operationName}(...)`, element, { $$inheritExpandSelect: true });
activateActionsPromises.push(operation.execute("$auto", false, null, /*bReplaceWithRVC*/ true));
}
These two approaches were tested in a Fiori Elements app with V2 and V4 respectively in the List Report and Object Page with a CAP backend and Draft enabled.
However, I still want to do this independently from Fiori Elements so that it can be used in a Freestyle application as well.Best of all, this should also be possible in the current maintenance versions.
Are these approaches a good approach or can something be improved?