Step 2: Configuring the Conditional Appearance of the Button
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).
Configure the availability as follows:
- Configure a condition that checks whether the
InvoiceNbrfield is not null, and make the action unavailable when the condition is true by using the IsDisabledWhen method. Do the following:- In the
Conditionsclass, define the condition, as the following code shows.public Condition HasInvoice => GetOrCreate(condition => condition.FromBql<Where<RSSVWorkOrder.invoiceNbr.IsNotNull>>()); - Make sure an instance of the
Conditionsclass is created in the staticConfiguremethod. - In the WithActions method of the screen configuration, register
the
CreateInvoiceaction, as the following code shows.actions.Add(graph => graph.CreateInvoiceAction, action => action.WithCategory(processingCategory) .IsDisabledWhen(conditions.HasInvoice));By using the IsDisabledWhen method, you have specified that the action is unavailable when the provided condition is true.
- In the
- Add the action to only the workflow states where it is available (that is,
PendingPaymentandCompleted), as the following code shows..WithActions(actions => { actions.Add(graph => graph.CreateInvoiceAction, action => action.IsDuplicatedInToolbar() .WithConnotation(ActionConnotation.Success)); });
