Create recurring sales invoices automatically

A common issue is to generate invoices per month for items and services automatically, which are being sold periodically.

You can use report “Create recurring Sales Invoice” to generate sales invoices with the needed lines manually. The parameters “Order Date” and “Posting Date” in the request page are mandatory. So, the report cannot be used to generate invoices automatically without setting the mandatory parameters.

But one step after the other.
First goto “Recurring sales lines” and create a new record, set code and description and add a line with the item, which should be added in the sales invoice, when a new sales invoice will be created.

Next open the customer, for which the sales invoices with recurring lines should be created for. There goto Navigate/Sales/”Recurring sales lines” and add a new record with code “LIC”. Set additional values if needed.
Now, if a new sales invoice with that customer is created, the recurring lines are added automatically. That’s fine.

Next run report 172 “Create recurring sales invoices” to create sales invoices with recurring lines, semi-automatically. In the Request page set “customer no.” with the customer’s no. from above, also set the Code from the “Recurring sales lines”.

Fields “Order Date” and “Posting Date” are mandatory to run the report. Therefore it cannot run automatically without setting both date fields.

What to do now?
To run the report automatically e.g. monthly, the best choice is using a job queue entry. There the request page default values can be set. Set the filter fields like above, additional you could set a default value for the date fields. Doing that, the job queue entry can be run with no problem, but all invoices get then the default date value, what we do not want. It would be nice, if the current date is used.
To solve that  it could be an option to extend table “Standard Customer Sales Code”, if there would be a kind of “OnBeforeCreateSalesInvoice” event to replace the dates, but there isn’t.

So i decided to create a copy of report 172 and make one change.

trigger OnPreReport()  begin  //-  if (CurrentClientType = ClientType::Background) or (CurrentClientType = ClientType::NAS) then begin    OrderDate := Today;    PostingDate := Today;  end;   //+   if (OrderDate = 0D) or (PostingDate = 0D) then     Error(MissingDatesErr);end;
Ok, preparation ready.
Now create a new “job queue entry” as above described and leave the date fields empty.
The job queue entry:
To run the report monthly on every 1st of the month set a dateformula in “Next Run Date Formula”, here use “CM+D1”.
cheers