cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Side Effect: Can the content of an Calculated / Virtual Field be updated in draft

gregorw
SAP Mentor
SAP Mentor
0 Likes
989

Hello SAP CAP and Fiori Elements Experts,

I try to follow the Side Effect Annotations: Examples --> Additional Features in SAP Fiori Elements for OData V4 in my sample project. But the annotation:

 @Common.SideEffects #effect: {
    SourceProperties: [taxPercentage],
    TargetProperties: [
      ComputedTotalWithTax,
      ComputedTax
    ]
  }

Doesn't update the content of the Computed fields when I change the taxPercentage. I’ve tried also with a virtual field where I’ve added the calculation in the handler:

  this.after("each", Orders, (order) => {
    order.VirtualTotalWithTax =
      order.total + (order.total * order.taxPercentage) / 100;
  });

But this resulted in an endless loop when switching to the edit mode. There the Fiori Elements App requested endlessly the field VirtualTotalWithTax.

Does anyone had success creating an example where a calculated field is updated while being in draft?

Best Regards
Gregor

Accepted Solutions (0)

Answers (1)

Answers (1)

akuller
Participant
0 Likes

Hi,

I asked the same question some time ago. The answer was that drafts are not supported and should be handled with a separate implementation. However, it was said that in the future there might be a default handling for calculated fields from the database.


my Solution is this:

this.after('PATCH', 'Positions', async (data) => {
  await UPDATE(Positions.drafts, data.ID).set`total = quantity * amount`
});
Harshi
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi @gregorw,
There has been an update in CAP and it now supports drafts with calculated elements https://cap.cloud.sap/docs/releases/nov25#calculated-elements-for-drafts
But I have still not had any success with the implementation. 

Kind regards,
H