Autorun AI Docs

How to Create and Connect a UI Process in Autorun

This tutorial shows the complete flow for creating a UI process and connecting it to a component event.


Super Fast Build: Prompt for Mileva

When the user clicks 'Create Invoice' on an Offer record, extract the offer details (customer, line items, amounts, terms) and create a new Invoice with that data pre-filled. Validate that the Offer status is 'Won' before creating the Invoice, and link the new Invoice back to the original Offer.


Steps:

1. Open Process Designer

  • Open Developer Toolbox (available only in Edit mode)
  • Click Process Designer
  • Click Add process in the upper right corner

2. Create a New Process

  • Rename the process from "New Process" to, for example: CreateInvoiceFromOffer
  • From the Type dropdown, select UI

3. Build the UI Process Flow

On the canvas:

  • The Start and End nodes are created automatically
  • From the Library, drag a Code block onto the canvas
  • Connect the nodes:
    • Start -> Code
    • Code -> End

A UI process must have a valid Start-to-End connection to execute.

Branching

A Code node with two outgoing connections follows the first path when the block's result is truthy, and the second when it is falsy. For anything more involved, write if statements inside the Code block.


4. Add Logic to the Code Block

  • Click the Code icon in the upper-right corner of the Code node
  • The editor opens with default code, for example:

console.log(context);

  • Replace it with your logic, then Save

Writing the code

Everything the process can do is reached through context. The row in scope is on context.event (button clicks, table rows) or context.router.id (detail pages). Data goes through context.sdk. UI control goes through context.component, context.toast, and context.redirect.

context.component.updateByName("btnCreateInvoiceFromOffer", "loading", true);

try {
  const result = await context.sdk.entities.getById({
    params: { entitySlug: "offers", recordId: context.router.id }
  });
  const offer = result?.data ?? result;

  if (!offer) throw new Error("Offer not found");
  if (offer.Status?.ID !== 3) {
    context.toast.error("Only a won offer can be invoiced.");
    return;
  }

  const created = await context.sdk.entities.create({
    params: { entitySlug: "invoices" },
    json: {
      Company: offer.Company?.ID,
      InvoiceDate: new Date(),
      TotalAmount: offer.TotalAmount,
      OfferId: offer.ID
    }
  });

  if (!created.success) throw new Error(created.message || "Could not create invoice");

  context.toast.success("Invoice created.");
  context.redirect("/invoices/" + created.id);
} catch (error) {
  console.error(error);
  context.toast.error(error.message);
} finally {
  context.component.updateByName("btnCreateInvoiceFromOffer", "loading", false);
}

Three things to know before your first process:

  • Never pass appSlug. The running app injects it. Hardcoding a slug breaks the process the moment the app is copied.
  • Every SDK call is asynchronous and must be awaited. Hooks such as sdkClient are illegal here — use context.sdk.
  • Writes auto-refresh the UI. create, update, and delete invalidate the entity cache on success. You do not need context.mutate.

The full library is documented in the UI Functions Reference.


5. Verify the process exists

  • Open the Processes list in Process Designer
  • Confirm CreateInvoiceFromOffer appears under UI Processes

6. Connect it to a component event

  • Click the gear icon on the component (button, table, form, page)
  • Find the event — On click, On load, On change, On save
  • Select CreateInvoiceFromOffer from the dropdown
  • Click Save

What the event payload is

Eventcontext.event
On click (button on a row or details page)The record in scope
On load (page)Usually null — use context.router.id
On change (field / table cell){ updates, innerValue } — see Event
On save (form)The record being saved

What counts as a change in onChange

Any modification of a field value: picking a customer, editing a quantity, changing a dropdown, typing in a table cell. Each one fires onChange.

If no UI process is attached, the field still updates visually — no extra logic runs.