Inkey Solution Logo
banner

Blogs

Cancel Multiple Posted Sales Invoices using Job Queue in MS Dynamics 365 Business Central using AL Code

, August 21, 2024 160 Views

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 Cancel Multiple Posted Sales Invoices in a batch using Job Queue in Business Central. A job queue in Microsoft Dynamics 365 Business Central is a feature that allows you to schedule and automate tasks to be executed in the background. This can be anything from data synchronization to custom code execution. By creating a custom job queue, you can automate specific business processes, like Cancel Multiple Posted Sales Invoices in a batch.

Requirement:

We recently encountered a requirement where we need to cancel multiple posted sales invoices in a batch. Rather than executing this task manually, we created a custom job queue in Business Central to automate the cancellation process.

Prerequisites:

  • Access to a Dynamics 365 Business Central instance with administrator privileges.
  • Visual Studio Code with AL Language extension installed.

Solution (Implementation Steps):

In Dynamics 365 Business Central, follow these steps to automate the cancellation of multiple posted sales invoices in a batch:

Step 1: Create a Custom Report in AL

  • In the Visual Studio Code, create a Custom Report in AL.
  • In the dataset, we define a data item for “Sales Invoice Header”.
  • Inside the Report, Within the “OnAfterGetRecord” trigger, we have used a Codeunit called “Correct Posted Sales Invoice”.
  • Inside the Codeunit “Correct Posted Sales Invoice” include a procedure named “CancelPostedInvoice” within the “Correct Posted Sales Invoice” codeunit, passing the “Sales Invoice Header” data as a parameter to handle the cancellation process for the sales invoices.
report 70101 Cancel_Posted_Sales_Invoice
{
    UsageCategory = ReportsAndAnalysis;
    ApplicationArea = All;
    ProcessingOnly = true;
    UseRequestPage = false;

    dataset
    {
        dataitem("Sales Invoice Header"; "Sales Invoice Header")
        {
            trigger OnAfterGetRecord()
            var
                CorrectPostedSalesInvoice: Codeunit "Correct Posted Sales Invoice";
            begin
                CorrectPostedSalesInvoice.CancelPostedInvoice("Sales Invoice Header");
            end;
        }
    }
}

Step 2: Publish and Install the Extension

  • After creating the custom job queue (report), the user needs to publish and install the extension in the Dynamics 365 Business Central instance.

Step 3: Create a Custom Job Queue Entry

With the custom job queue (report), the user can now create a job queue entry to schedule and automate the cancellation process.

  • Access your Business Central instance.
  • Navigate to “Job Queue Entries” and create a new job queue entry.
  • Fill out the necessary fields, such as Name, Report ID (which should point to the custom report), and Description.

Step 4: Set Up Job Queue Parameters

  • In the job queue entry, the user can specify parameters such as the schedule for when the job should run.
  • In the job queue report request page, specify the filters as shown in the below image.

  • Make sure to enable the job queue entry, and then save and run it. This will initiate the job queue, and it will automatically Cancel Multiple Posted Sales Invoices in a batch.

Step 5: Test the Customization

  • Test the customization thoroughly to ensure it works as expected and meets your business requirements

Output:

Conclusion:

Implementing a custom job queue to automate the cancellation of multiple posted sales invoices in a batch within Microsoft Dynamics 365 Business Central enhances operational efficiency. This solution eliminates the need for manual intervention, reducing errors and saving valuable time. By following the outlined implementation steps, you can create a robust custom job queue using AL code, streamlining the process of canceling sales invoices seamlessly. The custom report efficiently retrieves and cancels posted sales invoices based on specified criteria, providing an automated and reliable solution.

mm

Inkey

INKEY is your solution partner.
Our focus is to deliver you in-time intelligent innovative solutions ("key") for the problems in hand. Maintaining a quality standard right from the inception of a project is our top most priority.

Our team of talented professionals will execute your projects with dedication and excellence. We take ownership and accountability for the effort that goes into meeting our client’s needs.

Years of experience and proven success of delivering innovative custom solutions.

More posts by

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 2 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Drop file here

Would you like to digitize your business and put it on the cloud?
Do you need clear, concise reports for your organization?