Help ELMA BPM Platform
×
Menu

Dynamic Form

A dynamic form is a form with fields that change depending on the context of the process. You can use scripts to manage the content of dynamic forms.
There are two ways to specify a script that will change the form content:
In the task settings window, on the Form (Context) tab, in the Script for loading a form field, specify a script to be executed when the system loads the task form in Web Application;
In the task settings window, on the Form (Context) tab, open the context variable settings window, on the Additional tab specify a script to be executed when the value of the variable changes.
Attention!
Only those variables that change the form content can be defined by a Script On Value Change.
To specify a script for a task form, double-click the task activity in the graphic model; a task settings window opens. On the Form (Context) tab, in the Script for loading a form filed, select a script to be executed when the system loads the task form in Web Application (fig. 1).
Fig. 1. The Task settings window – The Form (Context) tab.
To specify a script executed when the variable value is changed, open the context variable properties on the Form (Context) tab. To do this, double-click on the variable name or select the variable in the Displayed Properties list and click Edit. In the opened window, go to the Additional tab, in the Script when changing the value field select a script to be executed when the value of the variable changes (fig. 2).
Fig. 2. The variable settings window. Selecting a script on change the variable value.
If you have specified a script when changing the value, next to the variable in the list you will see the icon (fig. 3).
Fig. 3. The Displayed properties list. The variable with the specified script.
Attention!
If a Block type property is added to a form as a nested object property, the scripts specified on this tab will not be executed.
Example of the dynamic form
Take for example the following form for approving an equipment request:
Fig. 4. The dynamic task form. The original form.
As you can see, the original form contains many fields. On its basis you can configure a new dynamic form. If the requested amount is less than 1000, the payment method is "cash" and the expected payment day is the next business day. If the requested amount is more than 1000, the payment method is "cheque" and the amount can be paid within four business days. The fields must be editable, the field Reason for amount change must be hidden. The Script when loading the form:
public virtual void OnFormLoad (Context context, EleWise.ELMA.Model.Views.FormViewBuilder form)
{
     int DaysToPay; // initialize a variable to store the days before the expected date of payment
     context.ChoosePaymentMethod = new DropDownItem (); // initialize a variable to set the payment method 
     if (context.Amount.Value <= 1000)// estimate the value of the context variable "Amount"
     {
          context.ChoosePaymentMethod.Value = "cash"; // Assign a "cash" value to the "Payment Method" variable
          DaysToPay = 1; // 1 business day before payment
     } else // if the amount is more than 1000
     {
          context.ChoosePaymentMethod.Value = "cheque"; // Assign a "cheque" value to the "Payment Method" variable
          DaysToPay = 4; // 4 business days before payment
     }
     int RealDays = 0;
            // initialize a variable to store the number of counted calendar days
            // in the next cycle the business days are counted with respect to the calendar days, excluding the weekends
            while (WorkDaysCount < DaysToPay) {
                if ((DateTime.Today.AddDays (RealDays).DayOfWeek != DayOfWeek.Saturday) && (DateTime.Today.AddDays (RealDays).DayOfWeek != DayOfWeek.Sunday)) {
                    WorkDaysCount++;
                }
                RealDays++;
            }
            context.DateOfPayment = DateTime.Today.AddDays (RealDays);
            // add to the calculated number of the calendar days to  the current date
            context
            form.For(c => c.ReasonForAmountChange).Visible = false; // Hide the field "Reason for Amount Change        }
}
Fig. 5. The example of the dynamic task form. The system automatically fills in the fields.
Define the script when changing the Amount value:
public virtual void OnAmountChange (Context context, EleWise.ELMA.Model.Views.FormViewBuilder form)
        {
            OnFormLoad(context, form);
            form.For(c => c.ReasonForRejection).Visible(false); // Hide the field "Reason for Rejection"
            form.For(c => c.ReasonForAmountChange).Visible(true); // Show the field "Reason for Amount Change"
        }
    }
Now if you change the value in the Amount field, the form will change according to the script:
Fig. 6. The example of the dynamic task form. The result of changing the value of the Amount field.
At this point, the setting of the dynamic task form is completed.
You can also add context variable value validation to a dynamic form. To learn more, see the respective Help page.

Copyright © 2006–2019 ELMA