How to create a custom approval Workflow in D365 Business Central (2024)

In my previous posts, we learned how to create new tables and pages, and also how to customize standard base objects.

In today's post, we will learn how to enable workflow.

If we require approval workflow for purchase, sales order etc… we enable standard workflow of Dynamics BC 365.

In our case, we need a customized workflow for our Claim.

Pre-Requisites

  1. Dynamics Business Central 365
  2. Claim Management Extension

You must achieve the two earlier Workshops to develop the Claim Management Extension.

Developing Extension in AL Using Visual Studio Code – Part 1

Developing Extension in AL Using Visual Studio Code – Part 2

Steps:

  1. Manage Approval status for each claim document
  2. Add "Approval Status" field to Claim Card and buttons to handle approval request entries.
  3. Create events for workflow
  4. Add events to library
  5. Check workflow (Activated or No)
  6. Handling workflow response
  7. Setup claim workflow
  8. Access record from the approval request page
  9. Publish & Enjoy
IDRange for our extension will be from 60011 to 60015

Manage Approval Status for each claim document

We need to extend Claim table by adding a new field "Approval Status" with option string as (Open,"Pending Approval",Released)

Extend Claim table and add new field "Approval Status".

Create new file Tab60000-Ext60011ClaimExt.al and add code like below:

How to create a custom approval Workflow in D365 Business Central (1)

As you see, we got an error: The target Table Claim for the extension object is not found.

This is because we are trying to extend an extension.

So before, we need to specify the dependency to the parent extension in the app.json file of our child extension. (Claim Workflow)

Note: The parent extension (ClaimManagementExt) should be published.

How to create a custom approval Workflow in D365 Business Central (2)

The dependencies property accepts an array of value, so we can specify multiple dependency extension.

Add "Approval Status" field to Claim Card and buttons to handle approval request entries.

  • Add "Approval Status" field and Approve button

Create new file Pag60000-Ext60011.ClaimExt.al

How to create a custom approval Workflow in D365 Business Central (3)

  • Add "Send Approval Request" & "Cancel Approval Request" buttons and trigger it.

To implement this, we first need to create new Codeunit 60014 "Approval Mgmt. Ext" and add two functions like below

How to create a custom approval Workflow in D365 Business Central (4)

Once done, go back to Claim page extension and add buttons like below:

How to create a custom approval Workflow in D365 Business Central (5)

We will add code on the OnAfterGetRecord trigger of the page to handle visibility of each buttons:

How to create a custom approval Workflow in D365 Business Central (6)

Global variables:

How to create a custom approval Workflow in D365 Business Central (7)

Create events for workflow

Now we need to create events for the workflow hence create a new Codeunit 60012 "Workflow Event Handling Ext" and add functions:

RunWorkflowOnSendClaimForApprovalCode : This is a global function with return value as Code and length 128

RunWorkflowOnSendClaimForApproval : This is a global function which is a Subscriber to the publisher Integration event OnSendClaimForApproval created earlier in "Approval Mgt Ext" Codeunit

RunWorkflowOnCancelClaimApprovalCode : This is a global function with return value as Code and length 128

RunWorkflowOnCancelClaimApproval : This is a global function which is a Subscriber to publisher Integration event OnCancelClaimForApproval created earlier in "Approval Mgt Ext" Codeunit

How to create a custom approval Workflow in D365 Business Central (8)

Add events to library

To populate the Workflow Event Table with our new events, we need to add two function on Codeunit "Workflow Event Handling Ext"

OnAddWorkflowEventsToLibrary : This is a local function which is a Subscriber to publisher Integration event OnAddWorkflowEventsToLibrary located on standard codeunit "Workflow Event Handling"

OnAddWorkflowEventPredecessorsToLibrary : This is a local function which is a Subcriber to publisher Integration event OnAddWorkflowEventPredecessorToibrary located on standard codeunit "Workflow Event Handing"

How to create a custom approval Workflow in D365 Business Central (9)

Global Variable:

How to create a custom approval Workflow in D365 Business Central (10)

Once done and before proceeding with Workflow response creation, we will add some functions to our "Approval Mgt Ext" Codeunit to determinate whether the workflow is activated or no and to populate the "Approval Entry" table with Claim Document No.

Check workflow (Activated or No)

Open "Approval Mgt Ext" codeunit and create three more functions:

CheckClaimApprovalsWorkflowEnable & IsClaimDocApprovalsWorkflowEnable: These are global functions with return value as boolean

OnPopulateApprovalEntryArgument: This is a local function which is a Subscriber to publisher Integration event OnPopulateApprovalEntryArgument located on standard codeunit "Approval Mgmt."

How to create a custom approval Workflow in D365 Business Central (11)

Global variables:

How to create a custom approval Workflow in D365 Business Central (12)

Handling workflow response

When Sending, Canceling or Approving a Request Approval Entries, the "Approval Status" of our claim document must be update.

To manage this, we create a new codeunit "Workflow Response Handling Ext" and add functions:

OnOpenDocument: This is a local function which is a Subcriber to publisher integration event OnOpenDocument located in standard codeunit "Workflow Response Handling".

OnReleaseDocument: This is a local function which is a Subscriber to publisher integration event OnReleaseDocument located in standard Codeunit "Workflow Response Handling".

OnSetStatusToPendingApproval: This is a local function which is a Subcriber to publisher integration event OnSetStatusToPendingApproval located in standard Codeunit "Approval Mgmt."

How to create a custom approval Workflow in D365 Business Central (13)

Now we need to add relation between our events and response.

To meet the needs, we will subscribe to publisher integration event located in standard Codeunit "Workflow Response Handling".

Add a subscribe event function like below:

How to create a custom approval Workflow in D365 Business Central (14)

Setup claim workflow

We can setup our new workflow manually or by code.

In this topic, we will see how to implement a new Workflow Template by code.

Worklfow template are created through codeunit 2 (Company-Initialize) calling the function InitWorkflow in Codeunit 1502 (Workflow Setup).

So, we will subscribe to some functions event integration base on this codeunit (Workflow Setup) to handle this.

Create a new Codeunit 60011 "Workflow Setup Ext" and add functions:

OnAddWorkflowCategoriesToLibrary:

This is a local function which is a Subcriber to publisher integration event OnAddWorkflowCategoriesToLibrary located in standard Codeunit "Workflow Setup" .

OnAfterInsertApprovalTableRelations:

This is a local function which is a Subcriber to publisher integration event OnAfterInsertApprovalTableRelations located in standard Codeunit "Workflow Setup" .

OnInsertWorkflowTemplates:

This is a local function which is a Subcriber to publisher integration event OnInsertWorkflowTemplates located in standard Codeunit "Workflow Setup" .

How to create a custom approval Workflow in D365 Business Central (15)

InsertClaimApprovalWorkflowTemplate: This is a local function which will populate the Workflow table and mark It as template.

InsertClaimApprovalWorkflowDetails: This is a local function which will initialize Event with and Response for our Workflow

To initialize steps for the workflow, we will use standard function "InsertDocApprovalWorkflowSteps" located in "Workflow Setup" Codeunit

BuildClaimTypeConditions: This is a local function which will build condition for event.

How to create a custom approval Workflow in D365 Business Central (16)

Global Variables:

·WorkflowSetup : Codeunit 1502

·ClaimWorkflowCategoryTxt : TextConst ‘CDW’

·ClaimWorkflowCategoryDescTxt : TextConst ‘Claim Document’

·ClaimApprovalWorkflowCodeTxt : TextConst ‘CAPW’

·ClaimApprovalWorkfowDescTxt : TextCont ‘Claim Approval Workflow’

·ClaimTypeCondTxt : TextConst ‘<?xml version = “1.0” encoding=”utf-8” standalone=”yes”?><ReportParameters><DataItems><DataItem name=”Claim”>%1</DataItem></DataItems></ReportParameters>

How to create a custom approval Workflow in D365 Business Central (17)

Access record from the approval request page

To access the record from the approval request page, we need to subscribe to event integration function located in standard codeunit "Page Management".

Create new codeunit 600015 "Page Management Ext" and add code like below:

How to create a custom approval Workflow in D365 Business Central (18)

Publish & Enjoy

How to create a custom approval Workflow in D365 Business Central (19)

Here we are …. Now you need to publish the extension and setup approval user.

Our workflow allow user to Send, Cancel or Approve approval request, but if we want to reject or delegate it?

I Invite you to add thosefunctionalities

How to create a custom approval Workflow in D365 Business Central (2024)

FAQs

How to create a custom approval Workflow in D365 Business Central? ›

a) Navigate to settings: In Dynamics 365, go to the 'Settings' tab and select 'Processes. ' b) New Workflow: Click on 'New' to start a Custom Workflow and choose the entity it will relate to.

How do I create an approval workflow in Dynamics 365? ›

To configure an approval process, in the workflow editor, right-click the approval element, and then click Properties to open the Properties form.
  1. Name the approval process. ...
  2. Specify when the system automatically acts on the document. ...
  3. Specify when notifications are sent. ...
  4. Specify a final approver.
Feb 8, 2024

How do I create a custom workflow in Dynamics 365? ›

a) Navigate to settings: In Dynamics 365, go to the 'Settings' tab and select 'Processes. ' b) New Workflow: Click on 'New' to start a Custom Workflow and choose the entity it will relate to.

How do I add a workflow response in business Central? ›

In the On Condition field, leave the value as Always. In the Then Response field, choose the Select Response link. Then, on the Workflow Responses page, in the Select Response field, choose the Send approval request for the record and create a notification response. Choose OK.

How do I create a custom approval process? ›

Build the Approval Process
  1. Click. ...
  2. From Setup, enter Approval in the Quick Find box, then select Approval Processes.
  3. Select an object from Manage Approval Process For. ...
  4. Click Create New Approval Process, then select Use Standard Setup Wizard.
  5. Enter a name in the Process Name field.

What is the step to create approval workflow? ›

To create an approval workflow, add the Approvals - Start and wait for an approval action to any flow. After you add this action, your flow can manage the approval of documents or processes. For example, you can create document approval flows that approve invoices, work orders, or sales quotations.

What is the approval workflow functionality? ›

An Approval workflow is a SharePoint feature that routes a document or other item stored in a SharePoint list or library to one or more people for their approval or rejection. The workflow automates, streamlines, and standardizes the whole process.

What elements are required for a workflow approval process? ›

Elements of a typical approval workflow process
  • Task submission portal. Approval processes usually start with submitting an invoice, document, or purchase order. ...
  • Defined approvers. ...
  • Established permission levels. ...
  • Set timelines. ...
  • Automated notifications. ...
  • Activity log.
Jul 25, 2023

What is the difference between custom workflow and actions in Dynamics 365? ›

Custom Workflows & Actions in Dynamics 365 Customer Engagement: Key Takeaways. Dynamics 365 workflows involve a series of steps and rules that automate a business process or task. Actions in Dynamics 365 are a type of process. Actions open a range of possibilities for composing business logic.

What is the difference between custom workflow and plugin in Dynamics 365? ›

Custom workflow could be configured with visual interface but plug-in could only be developed by Visual Studio and registered by Plug-in Registration Tool. So custom workflows are much more user-friendly for non-developers.

How do I create an approval workflow in Microsoft? ›

To create an approval from the Approvals hub:
  1. Open the Approvals app in Microsoft Teams.
  2. Select New approval request.
  3. Fill in the name of the request, who needs to approve it, decide approval order, any additional info, and add an attachment if needed.
  4. Select Send.

How do I add custom code to workflow? ›

To add a custom code action to a workflow:
  1. In your HubSpot account, navigate to Automation > Workflows.
  2. Click the name of a workflow, or create a new workflow.
  3. Click the + plus icon to add a workflow action.
  4. In the right panel, select Custom code.

How do I create a custom approval in power automate? ›

Create approval flow
  1. Sign in to Power Automate.
  2. On the left navigation bar, select My flows.
  3. Select New > Automated-from blank.
  4. On the screen that opens, provide a name for your flow in Flow name.
  5. In Choose your flow's trigger field, search for SharePoint.
  6. From the list of triggers, select When an item is created.
Apr 14, 2023

Top Articles
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 6038

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.