logo

Dynamic forms for business process tasks: sum of block items

You can find examples of scripts for blocks in the "Working with blocks in scripts" article.

To calculate the total sum of a block's items you can use a typical change script linked to the block's variable. Such a script will be executed when a new item is added or an existing item is changed.

public void sum_items(Context context, EleWise.ELMA.Model.Views.FormViewBuilder<Context> form)
{
    context.listsum = 0;
     
    foreach (var item in context.productlist)
    {
        context.listsum+= item.price;
    }
}
 
 
Important
Do not call the item.Save() method when working with block items, because it can damage the database integrity.
In this example, the amount in the Price field is calculated everytime the block is changed.
 
 

Attachments