Step 2: Configuring the Conditional Appearance of the Action
The Create Invoice button on the form toolbar and the equivalent
command on the More menu should be available only if the repair work order has the
Pending Payment or Completed status and if no invoice for the order has been
created yet (that is, if the RSSSVWorkOrder.InvoiceNbr
field is null). You
can configure the availability by combining two capabilities of Workflow API as follows:
- Configure a condition that checks whether the
InvoiceNbr
field is not null, and disable the action when the condition is true by using the IsDisabledWhen method. Do the following:- In the
Conditions
class, define the condition, as the following code shows.public Condition DisableCreateInvoice => GetOrCreate(b => b.FromBql< Where<RSSVWorkOrder.invoiceNbr.IsNotNull>>());
- Make sure an instance of the
Conditions
class (conditions
) is created in theConfigure(WorkflowContext<RSSVWorkOrderEntry, RSSVWorkOrder> context)
method. - In the WithActions method of the screen configuration, register
the
CreateInvoice
action, as the following code shows.actions.Add(g => g.CreateInvoiceAction, c => c .WithCategory(processingCategory) .IsDisabledWhen(conditions.DisableCreateInvoice));
By using the IsDisabledWhen method, you have specified that the action is disabled when the provided condition is true.
- In the
- Add the action to only the states where it is available (that is, the
PendingPayment
andCompleted
states), as the following code shows..WithActions(actions => { actions.Add(g => g.CreateInvoiceAction, a => a .IsDuplicatedInToolbar() .WithConnotation(ActionConnotation.Success)); });