ZuloOne
English
Sign in
Menu

Ask from a command

Updated

A command script can stop, ask the user, and continue with the answer: Yes/No, a choice of buttons, or a small form. This page is the recipe. The two-run contract, the test harness, and the callers are Asking the user from a command.

Note

A static "Are you sure?" is requiresConfirmation on the command json. Use Confirm / Choose / Ask when the question depends on what the command found.

How to#

The calls live on CommandContext. Untyped bases also expose them as protected methods, so you can omit context.. The first argument is the question key. It must be unique inside the command: the client sends the answer back under this key.

if (shortage > 0 && !context.Confirm("negative",
        $"{shortage} pcs short. Post with a negative stock?"))
    return;

var how = context.Choose("split", "Split the order?",
    "By warehouse", "By date", "Keep");

var form = context.Ask("move", "Move the remainder",
    CommandQuestionField.Decimal("Qty", "Quantity", required: true,
        defaultValue: shortage),
    CommandQuestionField.Reference("Store", "Warehouse", "Store"));
var qty = form.Get<decimal>("Qty");
var store = form.Get<Guid?>("Store");

Confirm returns true or false. Choose returns the caption of the button. Ask returns a bag; CommandQuestionField has Text, LargeText, Integer, Decimal, Boolean, Date, DateTime, and Reference (dictionary by name or by metaId).

The server does not keep the request open. The command runs again with answers until every key is filled. Closing the dialog cancels. An integration test passes answers:; without them the result reports AwaitingAnswer.

Warning

Everything the command did before the question happens again on the next run. Ask before you write: before SaveDocumentAsync, before creating records, before a service that posts. Do not wrap a question in catch (Exception) — that swallows CommandQuestionException, and the command continues as if the user had answered.

A wrap still calls nextAsync and sees the same answers — Chain of Command.

What's not there yet#

Questions from object events and from services called outside a command. A question on the mobile client. Form modules. Details: Asking the user from a command.

Where next#

Was this page helpful?