Entradas

How to Merge PDF Files in Business Central Using a Python API

Imagen
  When working with documents in Microsoft Dynamics 365 Business Central, sometimes we need to combine multiple PDF files into a single document — for example, when generating a bundle of invoices or reports. In this post, I’ll show you how to achieve that by integrating Business Central AL code with a Python-based API using FastAPI and PyPDF2. 🐍 The Python API (FastAPI + PyPDF2) We’ll expose a /merge-pdf endpoint using FastAPI that: Accepts a list of PDFs encoded in Base64 Merges them using PyPDF2.PdfMerger Returns the combined PDF as a Base64 string Here’s the Python code: python from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel import base64 from PyPDF2 import PdfMerger from io import BytesIO app = FastAPI() class PDFRequest ( BaseModel ): archivos_pdf: list [ str ] # List of Base64 PDF files class PDFResponse ( BaseModel ): pdf_unido: str # Base64-encoded merged PDF API_KEY = "YourApiKey" ...

How to Upload Files to SharePoint from Business Central Using AL and Microsoft Graph API

Imagen
How to Upload Files to SharePoint from Business Central Using AL and Microsoft Graph API Uploading documents from Business Central to SharePoint is a common requirement for businesses aiming to streamline document management. Microsoft Graph API provides an efficient way to integrate these services. This blog explains the implementation using AL code. Overview We'll demonstrate how to: Authenticate using OAuth2. Prepare file content in Business Central. Upload the file directly to SharePoint using the Microsoft Graph API. Step-by-Step Explanation 1. Authentication To communicate securely with SharePoint, you must obtain an OAuth token: procedure GetOAuthToken() AuthToken: SecretText var ClientID: Text; ClientSecret: Text; TenantID: Text; AccessTokenURL: Text; OAuth2: Codeunit OAuth2; Scopes: List of [Text]; begin ClientID := 'your-client-id'; ClientSecret := 'your-client-secret'; TenantID := 'your-tenant-id'; ...

How to Print Multiple Copies in Report in AL of Microsoft Dynamics 365 Business Central

Imagen
  How to Print Multiple Copies in Report in AL of Microsoft Dynamics 365 Business Central (MSDYN365BC)? There are two parts in report AL Code RDL Layout (Similar to NAV). AL Code I have pasted the AL code for the Item List report. report 50129 ItemListReport {     UsageCategory = ReportsAndAnalysis;     ApplicationArea = All;     CaptionML = ENU = 'AL Item List ';     DefaultLayout = RDLC;     RDLCLayout = './ItemListReport.rdl';     dataset     {         dataitem(Item; Item)         {              dataitem(CopyLoop; "Integer")             {  ...

How to send emails with attachments in Business Cental AL

Imagen
Many times we find ourselves with the need to send a document from Business Central with attached files, from Sales Orders, Purchases or some other document. Below I will share a solution which works for the aforementioned. The following example is based on generating a Sales Confirmation and sending an email with two attachments. The first thing we will do is attach two files from the Sales Order. Then, from the new action created "Send Confirmation With Attachments", we press to send the email with the two attachments. When you execute the action, an email will arrive with the sales confirmation and the two attached data. From the AL code, we can customize the email sending with images or a more appropriate email body for the company. Below I link the source code. https://github.com/juancamilo0519/SendAttachWithBusinessCentral //How to Do in Business Central By Juan Camilo Camargo A. pageextension 50101 SalesOrderExt extends "Sales Order" {     actions     { ...

How to open any document in OneDrive from Business Central

Imagen
https://github.com/juancamilo0519/OpenInOneDrive   The following post explains how to open any document, in this case a Sales Order, from OneDrive in order to immediately share it with our work team: By pressing the Open in Onedrive button, Business Central will ask if we agree to use our OneDrive in our environment. Finally, our document opens directly from OneDrive and we can share it with our work team. Below is the source code: https://github.com/juancamilo0519/OpenInOneDrive //Whith this solution you can copy the file to your bussiness central folder in OneDrive and open it in a new windows. pageextension 50100 SalesOrderExt extends "Sales Order" {     actions     {         addlast ( "O&rder" )         {             action ( OpenInOneDrive )             {                 ApplicationArea = all;     ...

How to update the daily exchange rate by consuming web services from any bank.

Imagen
Financial management users have the daily task of updating the exchange rate with respect to any foreign currency, however, this task is often done manually. In the next post, I will explain the simple way to consume a central bank web service in this case of Mexico (It works for any country) and updates the exchange rate table. It is important to know that for it to be done automatically, you simply need to expose a Job Queue that executes this update task daily. Below the source code: procedure GetRateforDateBanxico() var Client: HttpClient; Response: HttpResponseMessage; ContentTxt: Text; Root: JsonObject; CurRate: Decimal; CurRateTxt: text; CurDateTxT: Text; ExchangeRate: Record "Currency Exchange Rate"; BMSetup: Record "GetCurrfromBM Setup"; Pos: Integer; PosD: Integer; begin BMSetup.Get(); if Client.Get('https://www.banxico.org.mx/SieAPIRest/serv...

Join two or more PDFs into one in Business Central

Imagen
In the next post we will explain how to join two PDFs into one, we will take as an example the generation of a Sales Order in PDF and Sales Invoice in the same format. First we will create the codeunit as follows: Then we will create a page where we will generate the pdf of the Sales Order and the Sales invoice: page 50148 MergePDF {     Caption = 'MergePDF';     PageType = Card;     layout     {         area(content)         {             group(General)             {                 usercontrol(pdf; PDF)                 {                     ApplicationArea = all;                     trigger DownloadPDF(pdfToNav: text)               ...