Dynamic task form in business processes

You can control the content of the task form, (show or hide fields, mark fields as required, and change values of variables), by running scripts on load of a form and scripts on change of a value.

Events on change support the following types: all simple types (except for HTML-markup), objects, documents, listing. Blocks and properties are not supported. For the properties included in the list of ‘Displayed Variables’ of the task context you can control only the following parameters: show or hide fields and mark fields as required. If you want to hide a field when opening a task form, you must check the box ‘Script on the form loads’, and specify Visible = false for the property you want to hide.

Consider an example of creating a dynamic task form.

There is a variable ‘Customer Type’ of the ‘drop-down list’ type, which has two values: ‘individual’ and ‘company’. The process context also includes variables for each of the customer types that should be displayed only when the respective type is selected. In the task settings, on the ‘Context’ tab, select an appropriate script in the ‘script on the form load’ field. Select the same script in the settings window of the variable "Customer type" in the ‘script on the value change’ filed.

The script text is as follows:

public void UpdateVisibility(Context context, EleWise.ELMA.Model.Views.FormViewBuilder<Context> form)
        {
            var isIndividual = context.CustomerType != null && context. CustomerType.Value == "Individual"; // check the selected value in the variable ‘Customer type’
            var isCompany = context. CustomerType != null && context. CustomerType.Value == "Company";
            form.For(c => c.Name).Visible(isIndividual).Required(isIndividual); // whether to show or hide the field Name and mark it as required  
            form.For(c => c.CompanyName).Visible(isCompany).Required(isCompany);
            form.For(c => c. Insurance).Visible(isIndividual); // whether to show or hide the field which is not required  
            form.For(c => c. InsuranceNumber).Visible(isIndividual).Required(isIndividual);
        }

As a result, if you select ‘Individual’ as a customer type, three fields will appear on the task form: Name, Insurance and Insurance Number. If you select ‘Company’, the form will show one new field – ‘Company Name’.

You can also specify scripts for the Block property. It is possible to:

  1. Call blocks when changing variables that are not included in the block (show or hide, values).
  2. Specify scripts on change of blocks.
  3. Specify scripts on change of variables in the block.

In this case, an additional parameter "item" is passed to the script method. This is a block element, which has been changed. For example:

public void CalcSum(Context context, Unit item, EleWise.ELMA.Model.Views.FormViewBuilder<Unit> form)
{
item.Sum = item.Price.Value * item.Count;
}

Restrictions:

By using scripts on change of the block variables, you cannot change values or visibility parameters of the variable that are not included in the block. To do this, you need to set the script for the block.