Dynamics 365 Business Central: How to automatically delete completely invoiced documents (Using Job Queue)

Dynamics 365 Business Central

Hi, Readers.
Today, I would like to talk about a simple topic, how to automatically delete completely invoiced documents in Business Central.
First of all, the following descriptions are based on invoiced sales orders, and the same goes for other documents.

As you might know, in Business Central, after posting a sales invoice from the sales order page, the system will delete the completely invoiced sales order.

In case a sales invoice is created from the sales invoice page and use Get Shipment Lines functionality to do invoicing, the system will not delete the completely invoiced sales order.

So, what should you do if your process includes the above two operations and you do not want the invoiced orders to remain in the system?
It’s quite simple. In addition to manually deleting each order, in Business Central, you can delete invoiced documents with a batch job, such as Delete Invoiced Sales Orders.
You can find them in Tell me,

and on the Data cleanup tasks page (Data Administration page).

For example:

You can go and run it manually once a day, or once a week, but this can take quite a bit of time if it’s not just sales orders, but other things like purchase orders, service orders, blanket orders, etc.

So can it run automatically?
This time we are going to use the powerful task feature of Business Central, Job Queue.

Job queues in Business Central enable users to schedule and run specific Reports and Codeunits. You can set jobs to run one time, or on a recurring basis. For example, you might want to run the Salesperson * Sales Statistics report weekly, to track sales by salesperson each week, or you might want to run the Delegate Approval Requests codeunit daily, to prevent documents from piling up or otherwise block the workflow.

Choose the Tell Me icon, enter Job Queue Entries, and then choose the related link.

The Job Queue Entries page lists all existing jobs.

Choose New.

You need to specify information about the type of object you want to run, such as a Report or Codeunit, and the name and object ID of the object that you want to run.
This time the Object Type is Report and the Object ID is 299 (Delete Invoiced Sales Orders).

You can also add Report Parameters to specify the behavior of the job queue entry.

For example, delete only the invoiced sales orders with Sell-to Customer No. 40000.

The next important setting is the Recurrence, for example, runs at 3:00:00 PM every day.

You can also specify the date formula that is used to calculate the next time the recurring job queue entry will run. If you use a date formula, all other recurrence settings are cleared.

After you entered information such as parameters, time and date, recurrence, choose Process -> Set Status to Ready.

The Job Queue setting is complete.

Test Video:

Isn’t it so convenient?😃 Give it a try.

1. The user must have permission to run the particular report or codeunit, or an error will be returned when the job queue is run.

2. The following table describes the values of the Status field.

ReadyIndicates that the job queue entry is ready to be run.
In ProcessIndicates that the job queue entry is in process. This field is updated while the job queue is running.
On HoldDefault. Indicates the status of the job queue entry when it is created. Choose the Set Status to Ready action to change the status to Ready. Choose the Set On Hold or Suspend actions to change the status back to On Hold.
ErrorIndicates that there is an error. Choose Show Error to see the error message.
FinishedIndicates that the job queue entry is complete.

3. The Report ID and Name (As of 2021/08/11 BC18.3)

Object IDObject NameCaption
291Delete Invd Blnkt Sales OrdersDelete Invoiced Blanket Sales Orders
299Delete Invoiced Sales OrdersDelete Invoiced Sales Orders
491Delete Invd Blnkt Purch OrdersDelete Invoiced Blanket Purchase Orders
499Delete Invoiced Purch. OrdersDelete Invoiced Purchase Orders
5914Delete Invoiced Service OrdersDelete Invoiced Service Orders
6651Delete Invd Sales Ret. OrdersDelete Invoiced Sales Return Orders
6661Delete Invd Purch. Ret. OrdersDelete Invoiced Purchase Return Orders
5755Delete Registered Whse. Docs.Delete Registered Warehouse Documents

4. If you want to keep sales orders, you can use the standard archive feature.
Find more about Archive Documents in Microsoft Docs.

Find more about Use Job Queues to Schedule Tasks in Microsoft Docs.


Hope this will help.

Thanks for reading.



Copied title and URL