Dynamics Business Machine: business automation framework | Mage Series
The Power Platform (PP), specifically Dataverse (DV) and Dynamics apps, provides a lot of flexibility in defining complex business logic and flows, satisfying even the most intricate business requirements. However, with this flexibility comes complexity, especially in the design, development, and maintenance of business processes.
Let me introduce a new solution that simplifies and accelerates the process of implementing business flows while unifying logic and boosting overall performance.
Business logic fragmentation and duplication
In general programming, one of the biggest challenges is managing duplicated logic across different parts of an application. Consider the scenario where business logic must be validated on both the front end and the backend to ensure consistent critical rule enforcement. This redundancy is necessary due to the risk of bypassing front-end validations, either intentionally or inadvertently.
Frameworks like .NET MVC have attempted to solve this issue by providing mechanisms such as data annotations that allow developers to define validation rules once, which can then be enforced across both client-side and server-side layers automatically. This helps ensure consistency, improves maintainability, and reduces redundancy—thus adhering to the DRY (Don’t Repeat Yourself) principle.
However, in PP, this is quite limited. The platform has tools like Business Rules, but these are typically only suitable for simpler use cases and are not robust enough to handle more complex requirements across both the frontend and backend environments.
We need a practical method to “write once, run everywhere”.
SDKs everywhere
Another challenge when working with Power Platform is the variety of SDKs needed for different parts of the system. On the front end, developers use the JavaScript XRM SDK, while on the backend, plugins use a different IPlugin-related SDK. Adding web services or PowerFX further complicates things, requiring developers to deal with yet another layer.
This lack of standardisation not only increases the learning curve but also prolongs the time required to implement logic and keep things in sync. It becomes a challenge to manage, especially in larger projects. It keeps piling up!
We need to standardise our APIs to streamline development and ensure consistency across the entire stack.
DV Actions?
One potential solution is using Dataverse Actions to encapsulate business logic. By defining actions for each sequence, developers could call this logic from any part of the system, effectively creating a reusable API or even a rules engine. However, this approach comes with its own drawbacks.
Performance and complexity are the primary downsides. Creating many actions not only complicates maintenance but can also slow down overall system performance, particularly when many actions are chained together. Moreover, managing numerous actions introduces overhead in terms of understanding, documenting, and updating each action when requirements change.
We need an easier, more efficient way to define performant logic units.
Limitations of Business Process Flows
When Microsoft first introduced Business Process Flows (BPFs) over a decade ago, the concept promised much: flow guidance on the user interface that easily mapped out processes. While promising, the implementation faced several drawbacks:
- Limited depth in process flows, which restricts complex business logic.
- A basic and restrictive designer.
- Conditions that were too simple, lacking flexibility.
- No direct support for subprocesses or advanced stage control, such as sending back to previous stages easily.
- Customising logic was cumbersome, often requiring a combination of slow workflows and convoluted custom steps.
While excellent in theory, BPFs are often limited. In practice, they need an overhaul to reach modern standards.
Introducing The Business Machine (DBM)
Over a year ago, I wondered: What if we could just write all DV logic a la Node.js style? In other words, create a framework that allows you to “write once, run everywhere.”
The SDK
To make DBM work seamlessly, I chose JavaScript as the scripting language, as it integrates well with the browser environment without extensive porting efforts.
I integrated a JavaScript interpreter into the backend, resolving the write-once-run-everywhere issue. The framework was further refined to standardise APIs, reducing the complexity of implementing business logic across different endpoints (e.g., front-end, plugins, web services).
Code management and deployment
One of the key aspects of increasing adoption and usability is ensuring the code can be easily managed and deployed.
DBM provides a visual editor for users to manage JavaScript and JSON resources, which are saved as Web Resources. This approach provides proper source control integration, making deployment a breeze, as well as providing an interface to consistently edit code as it should be stored.
The machine is humming
With these elements in place, we now have a framework foundation that unifies logic and supports the creation of robust business flows. This framework paves the way for building a platform that significantly accelerates business automation.
Features
DBM is equipped with a user-friendly interface for managing code, creating new resources, and visually defining JSON trees to easily build or update record hierarchies. Here are some core features:
- Unified SDK: Use a standardised API for Dataverse services that works across the front end and backend environments.
- Modernised editor: Edit JavaScript code through an intuitive visual editor that integrates with Dynamics solutions as Web Resources.
- JSON tree editor: Easily create and manage record hierarchies through a JSON tree structure, enabling a simplified, visual approach to managing data.
- Enhanced business flow management: Design and manage business flows directly from the editor, with more advanced options to control stages, subprocesses, and handle intricate conditions.
- DV schema hierarchy: Define a table tree structure that supports inheritance.
- Integrated data: Include data in solution deployments for faster and more consistent deployments.
Below is the high-level roadmap planned for DBM.
Architecture
The architecture diagram below showcases the components involved in the DBM core:
Install
To get started, import the latest solution available at my GitHub repository: here.
Using the editor
Once installed, open the Yagasoft app, navigate to the ‘Dynamics Business Machine’ page, and you will see the following screen:
JavaScript script
- Start by clicking the “Add New Resource” button to create a new file within the editor.
- Provide a unique file name that ends with
.js
. - Set a display name for easy reference.
- Once the file is created, start writing your JavaScript code.
- After writing the code, save it as a web resource. This ensures that the script is properly version-controlled and easily integrated into Dynamics environments for deployment.
JSON
Same goes for JSON files. After adding the file, add a property, name it, and then write your code for the property.
SDK features
DBM comes equipped with a range of functionalities that help create, update, delete, and retrieve data from Dataverse, all using a unified JavaScript-based approach.
Context object
An object that is passed to the engine by the calling context. It is usually the Target row (entity).
$this
Service
The Dataverse service.
$service
Create
create(entity: Entity): Guid
const id = $service.create(new Ys.Entity('contact'));
Update
update(entity: Entity): void
const e = new Ys.Entity($this.logicalName, $this.id); e.attributes.lastname = 'Test!'; $service.update(e);
Delete
delete(id: Guid): void
$service.delete(Guid.parse('3a47b1ba-9537-ef11-8409-000d3adabdf3'));
Retrieve
retrieve(logicalName: string, id: Guid, columns: string[] | string): Entity
const r = $service.retrieve($this.logicalName, $this.id, 'firstname'); $log.info(r.attributes.firstname + ' ' + r.attributes.lastname);
RetrieveMultiple
retrieveMultiple(fetchXml: string, count?: number, page?: number): Entity[]
const rm = $service.retrieveMultiple(` <fetch> <entity name='contact'> <attribute name='createdon' /> <order attribute='createdon' descending='true' /> </entity> </fetch>`); $log.info(rm.length); $log.info(rm[0].attributes.createdon); $log.info(rm[0].attributes.parentcustomerid);
Execute code
For this initial release, DBM has a custom step that takes the following parameters:
- Script file: the web resource containing the script to run.
- Script file ID: the unique path of the file.
- Inline script: hard code a script to run.
- Inline script type: what type of script is hard coded.
- JSON script action: action to execute on a JSON script if given.
You must provide a value for parameters 1, 2, or 3. Param 4 is required if 3 is given. Param 5 specifies the action if a JSON script is given (details below).
Current status
In development
- Front-end processor/VM
- Dynamics JS SDK mapping
- Map service functions to DV service requests
- Handle XRM SDK calls for backend processing
- Ignore UI functions and handle WebApi
- Implement DV SDK’s Execute method and OrganizationRequest class handling
- Implement HTTP requests
- XrmToolBox plugin
Future releases
In upcoming releases, DBM aims to include:
- Define complete business flows, with integrated logic and intricate control.
- Deeper integration with Dataverse events.
- Schema-as-a-Code enhancements, including table inheritance and embedded lookup data for faster deployments.
- Background job scheduling and execution features.
For more details, please refer to the diagram in the ‘features’ section.
Accelerate your business flow development
The Dynamics Business Machine represents an innovative solution to modernise how business logic and flows are created and maintained in Microsoft Power Platform. By unifying logic and providing a more intuitive development interface, DBM aims to help developers increase efficiency, reduce redundancy, and deliver more advanced business processes.
For more information, check out the GitHub repository.