Microsoft Dynamics 365 Business Central is a powerful Enterprise Resource Planning (ERP) solution that offers a wide range of customization options to meet the unique needs of your business. One such customization is to call (invoke) Power Automate Flows on an action via HTTP Request in Business Central Using AL Code. Integrating Power Automate Flows with Business Central via HTTP requests using AL code provides a powerful mechanism for automating business processes and enhancing productivity.
We recently encountered a requirement where we need to trigger (invoke) a Power Automate Flow when a user clicks on a specific action within Business Central.
In Dynamics 365 Business Central, follow these steps to call (invoke) Power Automate Flows on an action via HTTP Request:
Step 1: Create the Action in AL
Define an action within the AL codebase. This action contains a trigger named OnAction() which executes when invoked. Within this trigger, an HTTP request is crafted to call the designated Power Automate Flow.
action("Action") { ApplicationArea = All; Image = SelectMore; Promoted = true; PromotedCategory = Process; trigger OnAction() var HttpContent: HttpContent; HttpClient: HttpClient; HttpHeaders: HttpHeaders; HttpRequestMessage: HttpRequestMessage; HttpResponseMessage: HttpResponseMessage; Content: Text; GetEmailId_From_Current_User: Text; responseText: Text; No: Text; Var_UserId: Text; UserTable: Record User; begin // Get the current user's ID Var_UserId := UserId; // Find the user record based on the user ID UserTable.SetRange("User Name", Var_UserId); if UserTable.FindSet() then begin // If user record found, get the email ID associated with the current user GetEmailId_From_Current_User := UserTable."Authentication Email"; end; // Construct JSON content to send in the HTTP request Content := '{ "No.": "' + No + '" , "EmailId": "' + GetEmailId_From_Current_User + '"}'; // Write content to HttpContent object HttpContent.WriteFrom(Content); // Get headers for the HTTP request HttpContent.GetHeaders(HttpHeaders); // Clear existing headers HttpHeaders.Clear(); // Add Content-Type header HttpHeaders.Add('Content-Type', 'application/Json'); // Set the content and URI for the HTTP request message HttpRequestMessage.Content := HttpContent; HttpRequestMessage.SetRequestUri('HTTP_URL_of_Power_Automate_Flow'); // Set the HTTP method to POST HttpRequestMessage.Method := 'post'; // Send the HTTP request HttpClient.Send(HttpRequestMessage, HttpResponseMessage); // Read the response content HttpResponseMessage.Content().ReadAs(responseText); end; }
Step 2: Replace HTTP URL of Power Automate Flow
Replace the placeholder ‘HTTP_URL_of_Power_Automate_Flow’ in the AL code with the actual HTTP URL of the Power Automate Flow to be invoked.
Step 3: Publish and Install the Extension
Publish the AL code as an extension and install it in your Dynamics 365 Business Central instance.
Step 4: Test the Customization
Trigger the action within Business Central to invoke the Power Automate Flow via HTTP request. Verify the execution and response to ensure successful integration.
Integrating Power Automate Flows with Dynamics 365 Business Central through HTTP requests using AL code facilitates streamlined automation of business processes. By following the outlined steps, businesses can efficiently orchestrate workflows, thereby enhancing productivity and agility in their operations.
© All Rights Reserved. Inkey IT Solutions Pvt. Ltd. 2024
Leave a Reply