Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 38 ยท Model-driven Apps

Business Rules and Command Bar Commands

Add logic to model-driven Power Apps with business rules (conditions and actions on forms) and command bar buttons built with Power Fx. Includes stand-ins.

A model-driven app is not only data and forms. You also want rules ("a discount over 20% needs a reason") and actions ("a button that marks the request as approved"). Power Apps gives you two low-code tools for this: business rules for form and data logic, and commands for buttons on the command bar.

Business rules

A business rule is a condition plus actions, built in a visual designer with no code. Open a table, choose Business rules, then Add business rule. The designer shows a canvas with a Condition node and an action area.

A rule can:

  • Set a column's value.
  • Set a column as business required or optional.
  • Show or hide a column.
  • Enable or disable (lock) a column.
  • Validate data and show an error message.
  • Set a default value.
  • Recommend a value (show a suggestion).

Each rule has a scope: Entity (all forms, plus server-side enforcement), All forms, or a single form. With Entity scope, the rule also runs on the server when data arrives through an API or import, so it cannot be bypassed from the user interface. Hide/show and enable/disable only make sense on forms.

Example: "If Discount is greater than 20, make Reason business required and show an error if Discount is above 50." That is a condition (Discount > 20) with the actions "set Reason required" and, in a second branch, "show error message".

Business rules are limited: they work on columns of the same row (and one parent row, in some cases), not on arbitrary related data. For cross-table or multi-step logic use a flow (Power Automate) or a plug-in.

A business rule as data: a stand-in

A rule is a declarative object. This stand-in evaluates the example above against a row. It is a teaching model, not Dataverse's engine.

JS Stand-in: evaluating a business rule

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Commands

The command bar is the row of buttons at the top of a view or form (New, Delete, Refresh). Modern commanding lets you add your own buttons:

  1. In the app designer, choose the page (table), then Edit command bar.
  2. Pick where it appears: Main grid, Main form, Subgrid or Associated grid.
  3. Choose New, then Command.
  4. Set the Label and Icon.
  5. Under Action, choose Run formula (Power Fx) or Run JavaScript.
  6. Under Visibility, choose Show on condition from formula to decide when the button appears.
  7. Save and publish.

A Power Fx command can use functions such as Patch, Notify, Navigate and SelfHelp.Selected-style context. In a form command you refer to the current row with Self.Selected.Item; in a grid command, Self.Selected.AllItems is the table of selected rows. A typical "Approve" button's Action formula looks like this (read-only, because the product cannot run here):

TEXT
Patch(Requests, Self.Selected.Item, { Status: 'Status (Requests)'.Approved });
Notify("Request approved", NotificationType.Success)

and its Visibility formula:

TEXT
Self.Selected.Item.Status = 'Status (Requests)'.Submitted

Choice column values are written with the choice set's name, which is why 'Status (Requests)'.Approved looks different from a plain string. Dataverse choice columns are covered in the data chapter of this course.

Business rule or command?

Business rule Validate, require, show/hide
Command A button that does something
1 / 2

Simulating a visibility formula

A command's visibility formula is just a boolean expression over the selected row. This stand-in shows which buttons would appear for different rows.

JS Stand-in: which commands are visible?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Good practices

  • Name rules clearly ("Discount over 20 needs reason") so others know their purpose.
  • Prefer Entity scope for rules that protect data integrity.
  • Keep one idea per rule; chains of rules are hard to debug.
  • Test with the Monitor tool (Monitor and Testing) to see which rules ran.
  • Always provide an error message that tells the user what to fix.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which business rule scope also runs on the server for API and import data?

    Entity scope is enforced server-side, so it applies to any data entry path.
  2. 2. Which is NOT something a business rule can do directly?

    Business rules work on columns and form behaviour. External calls need a flow or plug-in.
  3. 3. Where do you add a custom button to a model-driven app?

    Modern commanding adds commands through Edit command bar in the app designer.
  4. 4. What controls whether a command is shown?

    Visibility is set with a Power Fx formula returning true or false.

Summary

  • Business rules add visual condition/action logic to columns and forms; Entity scope is enforced on the server.
  • Commands add buttons to the command bar with Power Fx or JavaScript actions and visibility formulas.
  • Complex or cross-table logic belongs in flows or plug-ins.
  • Keep rules small, named and tested.

Next: Site Maps, Dashboards and Charts