Continuing the saga of server-side validation in Power Pages and reiterating the issue:
Sometimes people add business logic in standard or custom forms using JavaScript. However, this approach only works on the client side, meaning it can be bypassed if someone manipulates the DOM or interacts directly with the Web API (e.g., using browser dev tools or custom scripts).
I already explained how you could add validation using:
However, we have an additional option for basic logic scenarios: Dataverse Classic real-time workflows.
What are Classic Workflows?
Classic workflows in Dataverse provide a no-code way to automate processes and enforce logic on record creation, updates, or deletions (since the early Dynamics days).
They can be configured to run in real-time (synchronously) or in the background (asynchronously), and they support conditions, branching, and actions like field updates, email sending, or even stopping the process with a custom message in real-time workflows.
Unlike business rules, classic workflows support more complex logic, including access to related records and comparisons between previous and current values (when using real-time workflows). They also run on the server side, making them useful for Power Pages scenarios where client-side rules based on scripts can be bypassed
Creating a Classic Workflow for Validation
Go to your solution and click New / Automation / Process / Workflow:
Click New and create a new workflow for your target table (e.g., Case, Ticket, or a custom table).
Uncheck Run workflow in the background. This will make sure it runs on real time when we make our updates.
In the options for automatic process, keep the scope as Organization so it will run on any record updated. Select start when Record is created and when Record fields change.
Select the fields you want to trigger the update (in my case, Support Ticket Status):
Add a check condition step:
That looks for Status equals Completed or Cancelled AND Modified By Full Name (related entity) contains “# Portals” (Power Pages application user will usually show this format):
If the condition is true, use the Stop Workflow action:
And select the option to cancel the operation with a custom error message (e.g., “You cannot update those statuses via Portal.”):
Final layout:
Save and activate the workflow.
Testing the Workflow
Now, if you try to create or update a record using the Power Pages Web API using one of the restricted statuses, the workflow will intercept and cancel the operation with the message you defined.
When trying to use valid statuses, the creates or updates work normally:
Conclusion
Classic workflows provide a simple and effective way to add server-side validation logic in Dataverse, and unlike business rules, real-time workflows can reference related entities, giving you a bit more flexibility as a no-code option
References.
Microsoft Dataverse Real Time workflows – Microsoft Learn
The post Power Pages: Using Dataverse Classic real-time Workflows for Server-Side Validation of Web API Calls appeared first on michelcarlo.