logo

Dynamic forms for business process tasks: Scripts for editing block items

Apart from editing a block item, you might need to work with certain fields inside the item itself. Such scripts differ from other dynamic form scripts. 
 
When you create a script for a block item, an additional item object appears:
public void calculate_item(Context context, P_Table_ProductList item, EleWise.ELMA.Model.Views.FormViewBuilder<P_Table_ProductList> form)
 
This additional object is required for managing the fields that are being edited. Since the changes made in the editing form are not saved in the process context right away, you cannot refer to the block by means of the context objects, because the data will be outdated.
Therefore remember to use the item object for operations with the item or its fields, otherwise, errors are highly probable.
 
Also, certain specifics of block item scripts do not permit execution of these scripts while editing the items in a table.
 
Take a look at this example with two scripts.
public void calculate_count(Context context, EleWise.ELMA.Model.Views.FormViewBuilder<Context> form)
{
    context.Numberofitems= context.ProductList.Count;
}
 
This code is executed when the block is edited, like in the previous example. 
 
The following script is executing in the editing form of the block item:
public void calculate_item(Context context, P_Table_ProductList item, EleWise.ELMA.Model.Views.FormViewBuilder<P_Table_ProductList> form)
{
    var manager = EntityManager<CurrencyRate>.Instance;
    var filter = InterfaceActivator.Create<CurrencyRateFilter>();
    filter.Currency = item.Currency;
    var result = manager.Find(filter, new FetchOptions(0, 1)).FirstOrDefault();
     
    item.PriceinEuro= result.Rate* item.Price;
}
 
 
Important
Do not call the item.Save() method when working with block items, because it can damage the database integrity.
Two tasks are solved here:
  1. Information from the Currency Rate object (it is a user object) is received
  2. The price is calculated and specified in the Price in Euro field of the Product List block
To use the filter in this way, you need to select the "Generate filter" checkbox in the Currency Rate object and select the Currency field. For that, go the Objects section, open the Currency Rate page, go to the Advanced tab and check "Generate filter". On the page of the Currency property check "Participates in search (filter)" in the Advanced tab. After publication, restart the server.