The Workflow Framework in Dynamics 365 Finance & Operations
Question 52 — Automating approvals with workflow types, elements and the state machine.
Interview Question
Model Answer (Short)
The Workflow framework automates business processes such as approvals and reviews. A workflow is built from elements: approvals (multi-step, with actions like approve/reject/request change), tasks (a single unit of work), automated tasks, and conditional decisions / manual decisions that branch the flow. To develop one, you create a workflow type (which generates a document class, a document contract/query and event handler classes), then author workflow approvals/tasks and finally assemble a workflow configuration in the client. The document's progress is tracked through a workflow state (a status enum on the table), and submission/actions are driven by the SubmitToWorkflow menu item and the workflow event handler methods.
Workflow Elements
Building blocks
- Approval — a multi-step element with actions like approve, reject, request change, delegate.
- Task — a single unit of work assigned to a user/role.
- Automated task — runs logic automatically without user interaction.
- Conditional / manual decision — branches the flow based on data or a user choice.
Developer artifacts
- Workflow type — the root artifact; wizard-generates the supporting classes.
- Document class (extends
WorkflowDocument) — exposes the data the workflow acts on. - Document query — defines the data source for the workflow document.
- Event handler class — implements
started,completed,canceled, etc. to update status. - SubmitToWorkflow menu item — placed on the form to submit the record.
Tracking document status
- A workflow status enum field on the table records progress (e.g. Draft, Submitted, Approved, Rejected).
- The event handler updates this status as the workflow moves through states.
- The form's workflow bar shows the current state and available actions to the user.
Prerequisites (Rule 5)
- Visual Studio with the Dynamics 365 developer tools.
- A custom model / package for your objects.
- A table with a workflow status enum field and a query for the document.
- A form with a SubmitToWorkflow menu item and workflow enabled.
Code Example — Workflow document class
// Exposes the data source query for the workflow
public class AbcOrderWorkflowDocument extends WorkflowDocument
{
public QueryName getQueryName()
{
return queryStr(AbcOrderWorkflowDoc);
}
}
Event handler — update status on completion
public class AbcOrderWorkflowEventHandler implements WorkflowCompletedEventHandler,
WorkflowCanceledEventHandler
{
public void completed(WorkflowEventArgs _args)
{
AbcOrderHeader header = AbcOrderHeader::findByRecId(
_args.parmWorkflowContext().parmRecId());
ttsbegin;
header.selectForUpdate(true);
header.WorkflowStatus = AbcWorkflowStatus::Approved;
header.doUpdate();
ttscommit;
}
public void canceled(WorkflowEventArgs _args)
{
AbcOrderHeader header = AbcOrderHeader::findByRecId(
_args.parmWorkflowContext().parmRecId());
ttsbegin;
header.selectForUpdate(true);
header.WorkflowStatus = AbcWorkflowStatus::Rejected;
header.doUpdate();
ttscommit;
}
}
Submitting a record to workflow (menu item handler)
// Called from the SubmitToWorkflow menu item on the form
public static void main(Args _args)
{
AbcOrderHeader header = _args.record();
// Launch the standard submit-to-workflow dialog
WorkflowWorkItemActionManager::main(_args);
}
Approval vs. Task Element
| Aspect | Approval | Task |
|---|---|---|
| Steps | Multiple steps supported | Single unit of work |
| Actions | Approve / Reject / Request change / Delegate | Complete / Return |
| Typical use | Sign-off on a document | An action to perform |
| Outcome | Approved or rejected | Done or returned |
Points the interviewer wants to hear
- Workflow automates approvals and business processes.
- Elements: approval, task, automated task, conditional/manual decision.
- Dev artifacts: workflow type, document class, query, event handler.
- Status is tracked with a workflow status enum updated by the event handler.
- Records are submitted via the SubmitToWorkflow menu item.
Likely Follow-up Questions
- What is the difference between an approval and a task element?
- Which classes does the workflow type wizard generate?
- How is the document's approval status kept in sync?
- How do you submit a record to a workflow from a form?
Key Takeaway
The Workflow framework automates approvals using approval, task and decision elements. Build it from a workflow type (document class, query, event handler), submit records via the SubmitToWorkflow menu item, and keep the status enum updated through the event handler.