action.skip

How to control the sort order of invoice line items?

← Billing & Invoice Management FAQ

Basically, the sort order of invoice line items is always controlled via the Sequence field.

In addition, there are other options that have an effect on the invoice line item listing:

Info

Note, however, that these options merely "overlap" the sequence but do not completely change it.

With respect to the sequence, there are various input factors that can determine this value, depending on the way you create invoices.

  • If you bill subscriptions, the sequence of the subscription items defines the sequence of the resulting invoice line items.

    When creating subscriptions and their items manually, JustOn sets a Sequence value as you add an item. If necessary, you can later edit the subscription items and modify the Sequence value as required.

    When automatically generating subscriptions, JustOn sorts the items alphabetically by their source object's Salesforce ID, assigning a corresponding Sequence value. If necessary, you can later edit the subscription items and modify the Sequence value as required.

  • If you generate invoices from arbitrary objects, JustOn sorts the invoice line items alphabetically by their source object's Salesforce ID, assigning a corresponding Sequence value.

Using the ON field mechanism, you can propagate customized sequence numbers to your subscription items or invoice line items.

Info

The actual way to implement this functionality in your org varies depending on your business requirements.

In broad outline, this involves the following major steps:

(1) Define the custom number field ON_Sequence on your source object.

(2) Depending on your requirements, you can have this field set manually by a user, or automatically via a formula. The formula may, for example, evaluate categorization data (product family, product code, order product number, etc.) to calculate a sequence number that reflects the intended sort order – if, for example, you want products of the category "A" to be placed on top of the list, your formula should produce a sequence number starting with 1.

(3) Create a batch setting record, setting an execution size > 1 for the relevant batch class, like, for example, 50 for BatchGenericInvoiceRun. This makes sure that JustOn considers the ON_Sequence field when evaluating the source records.

(4) When generating the subscriptions or invoices, JustOn copies the value calculated in the ON_Sequence field of the source object to the subscription item or invoice line item, respectively.

Example sequence formula

The following formula illustrates the sequence number generation. It evaluates a condition (order no. starts with SL). If that is true, it returns a sequence number made of a custom auto-number value prepended with 1, if not, prepended with 9.

IF (
BEGINS( ON_OrderNo__c , "SL"),
VALUE (LPAD ( ON_OpportunityProductNo__c , 6 , '1' )),
VALUE (LPAD ( ON_OpportunityProductNo__c , 6 , '9' ))
)

Note

Avalara AvaTax requires unique invoice line item numbers (sequence), which JustOn usually guarantees. If some custom configuration produces duplicate sequence values, make sure to correct the invoice line item numbering accordingly.