How to calculate the total amount of an order from its related order items in NocoBase 2.x?

Hi everyone,

I’m using NocoBase 2.x (Docker version).

I have two collections:

  • Orders
  • Order Items (Many-to-one relationship to Orders)

Each Order Item has a numeric field called amount (or price).

What I want to achieve is:

For each Order, automatically calculate the total amount, which is the sum of all related Order Items’ amount values.

In other words:

Order.total = SUM(OrderItems.amount)

What is the correct way to implement this in NocoBase 2.x?

  • Should I use Rollup?
  • Do I need a specific plugin?
  • Or is there another recommended approach?

Thank you in advance for your help!

Hello,
Please refer to
const total_count_en = await ctx.getVar(‘ctx.formValues.total_count_en’);
const total_count_cn = await ctx.getVar(‘ctx.formValues.total_count_cn’);
return total_count_en+total_count_cn;

const item = await ctx.getVar(‘ctx.formValues.m2m.item’);
return ctx.libs.formula.SUM(item);

1 Like

thanks expert