Dynamic forms for business processes: checkboxes for variables
The variables' forms have several checkboxes that regulate how the variables are shown in the task form:
- Visible – If it is false, then it is not shown in the task form;
- Required – if the field is required;
- ReadOnly – for reading only.
They are changed through form objects because only variable representation and not the meaning within the business process is concerned.
When a script is created, the form object also appears apart from the context:
EleWise.ELMA.Model.Views.FormViewBuilder<Context> form
Next, you can do the following modifications:
form.For(c => c.TIN).Visible(true)
where c => c.TIN is lambda function with the TIN context variable
public void set_visible(Context context, EleWise.ELMA.Model.Views.FormViewBuilder<Context> form)
{
try{
if (context.CustomerType.Value == "Individual")
{
form.For(c => c.TIN).Required(false).Visible(true);
form.For(c => c.PassportNumber).Required(true).Visible(true);
form.For(c => c.IssueDate).Required(false).Visible(true);
form.For(c => c.IssuedBy).Required(false).Visible(true);
form.For(c => c.ReasonCode).Required(false).Visible(false);
form.For(c => c.RegistrationNumber).Required(false).Visible(false);
form.For(c => c.Address).Required(false).Visible(false);
}
if (context.CustomerType.Value == "Company")
{
form.For(c => c.TIN).Required(true).Visible(true);
form.For(c => c.PassportNumber).Required(false).Visible(false);
form.For(c => c.IssueDate).Required(false).Visible(false);
form.For(c => c.IssuedBy).Required(false).Visible(false);
form.For(c => c.ReasonCode).Required(true).Visible(true);
form.For(c => c.RegistrationNumber).Required(true).Visible(true);
form.For(c => c.LegalAddress).Required(false).Visible(true).;
}
}
catch
{
form.For(c => c.TIN).Required(false).Visible(false);
form.For(c => c.PassportNumber).Required(false).Visible(false);
form.For(c => c.IssueDate).Required(false).Visible(false);
form.For(c => c.IssuedBy).Required(false).Visible(false);
form.For(c => c.ReasonCode).Required(false).Visible(false);
form.For(c => c.RegistrationNumber).Required(false).Visible(false);
form.For(c => c.LegalAddress).Required(false).Visible(false);
}
}
This script is called when the Customer Type variable is edited and when the form is loaded. When the form is opened for the first time while the Customer Type is not yet specified, catch is used, because the first checking will return a blank value error.
Depending on the Customer Type value, the script will change the Required and Visible properties for all the other variables in the form.