Skip to content

[Bug][SubscriptionBilling]: Printing multiple posted sales invoices from subscription contracts fails with duplicate record error #6973

@miljance

Description

@miljance

Describe the issue

When a user attempts to print more than one posted sales invoice generated from a subscription contract in a single print run, the operation fails with an error indicating a duplicate record in the billing details buffer.

The root cause appears to be that Sub. Contract Billing Printout (CodeUnit 8064) uses a shared buffer (FillContractBillingDetailsBufferFromSalesInvoice) that is not cleared or scoped per invoice, causing collisions when iterating over multiple invoices. Additionally, this likely results in billing details from one invoice bleeding into others in the printout.

Expected behavior

Printing multiple posted sales invoices from subscription contracts in a single run should succeed without errors. Each invoice should contain only its own billing details.

Steps to reproduce

  1. Create a subscription contract with at least one contract line.

  2. Run the billing process and post two or more sales invoices from the contract.

  3. Open the list of posted sales invoices, select multiple invoices generated from subscription contracts, and trigger Print.

    • ❌ The following error is thrown:

      The record in table Projektposten already exists. Identification fields and values: Lfd. Nr.='1'

    AL call stack:

    "Sub. Contract Billing Printout"(CodeUnit 8064).FillContractBillingDetailsBufferFromSalesInvoice line 82
    "Contract Standard Sales Inv."(ReportExtension 8008)."Header - OnAfterAfterGetRecord"(Trigger) line 2
    

Additional context

No response

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApprovedThe issue is approvedFinanceGitHub request for Finance area

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions