Sum of items


Actually I use Bonita Studio Community 7.5.4


I have created a form where I have a collection with a field called subtotal, therefore for each new collection another subtotal field is added so that they can be from 1 to 10,100 or 1000.


How can I add up all the subtotals that are generated?

I think the best way to do this is in a script because I need the total value to meet a condition on a gateway or if it is possible to do it from the form, could you give me ideas on how to do it!

Thanks in advanced!

2 answers


Hi Claudia,

Could you share the form? it will be easier

Any case, it is a matter of set the right variable names on the JS expression I proposed. Does not matter if it is the form created automatically or where the form is attached (task or process instantiation)



Hi Claudia,

Assuming you have in your form a variable invoice with following structure

    "customer":"Customer 1",
            "product":"product 1",
            "product":"product 2",

You can have an JS expression that does the math for subtotal and total of the invoice

if($data.invoice && $data.invoice.invoiceLines && $data.invoice.invoiceLines.length>0){
    var total =0;
        var subtotal = item.quantity * item.unitCost;
        item.subtotal = subtotal;
        total += subtotal;
    $ = total;


Submitted by claudia.avila_1... on Thu, 03/19/2020 - 18:21

Hi Pablo thanks for answering!

So the form is created automatically with the contract for this reason my unique variables is formInput and forOutput.

also it is the firts form to start a process the variable JS doesn't have problem with this? and how add the value in the formInput?

The structure of de formInput is somethig like that


{attach: null,

BDM variable:{
some variable of the contract : "",
Table:[{ subTotal}]
more variables: "",
total: ""