Invoices are numbered according to a pattern formed by adding dynamic prefixes and suffixes. Invoice Numbers usually contain the country code and other numeric or alphabetical identifiers that make an Invoice easy to track for different states or regions. Invoice numbering also helps in conforming to a legal or auditing requirement. With a couple of configurations, you can apply a sequential pattern of Invoice Numbering on all approved invoices. 

Note

Custom Number is not assigned to an Invoice on Creation. Only after the invoice is ‘Approved’ or an existing invoice transitions to the ‘Approved’ or 'Pending Approved' state, Custom Invoice Numbering is triggered.

Overview

When an Invoice is approved, value in the field Billing Country (which is derived from the Bill To address on Account) is matched with the value of country fields stored in a mapping table (Custom Numbering Field Mapping). Each country value has a corresponding code. The equivalent code is looked up in the Custom Numbering Entry table and the same format is applied for numbering the Invoice.


Note

The evaluation of a mapping is case-insensitive.  For example, if the mapping name is 'United States' and the Billing Country on an Invoice is 'united states' there will still be a match because the comparison is not case sensitive.

Use Case

Requirement:
Generate Invoices of the Format STG-xxxx-MT for Account 'OneTier' when the Billing Country in Billing Address is USA. Here, xxxx stands for a sequential numeric value which should start from 10.

Procedure: 

  1. Go to Setup > Custom numbering Field Mappings and make an entry for the country code. Set the Field Value as USA and Field Code as US.
     
  2. Go to Custom Numbering Entry Detail. Make following entries to form the numbering pattern:
    Field1 = US
    Object Type = Invoice
    Number Length = 4
    Prefix = STG
    Format Separator = -
    Suffix = MT
    Starting Number= 10
     
  3. Go to Custom Numbering Configuration Setting Detail and select Custom Numbering Enabled and Field One.
     
  4. Go to Invoice Runs, if you want to auto approve invoice, select auto approval. Alternatively you can go to Invoice detail and approve it manually. As soon as the Invoice status changes to 'Approved', you will see the Invoice Number.


Configurations

  1. Add a Custom Numbering Callback class.
    This callback class defines the actions to execute for Custom Numbering implementation.
    Go to Setup> Custom Settings > Billing Custom Classes and click Edit to specify the API Name of the callback class.
     
  2. Add optional Country Codes and Names under Custom Numbering Field Mapping.
    Go to SetupDevelop > Custom Metadata Types and click Manage Records for Custom Numbering Field Mapping.



    Enter the Field Value and Field Code and Save the mapping. Please ensure the Field Value specified here matches the Bill To Country Name on Account.
     
  3. Configure Custom Numbering Entry.
    This is where you can provide various numbering formats for Object Types such as Invoice, Credit Memos and Payments.
    Go to SetupCustom Settings , search for Custom Numbering Entry and click Manage. Click New to add a numbering entry.



    FieldDescription
    NameEnter a name for this entry for easy identification.
    Format SeparatorEnter a symbol ( hash, colon, or any other) to separate the Prefix, Number and Suffix. The separator helps to demarcate the dynamic and static fields of the format.
    Number LengthEnter the maximum length of an Invoice Number. This value accounts only for the number of digits in the Invoice Number sequence and not the prefix or suffix. The maximum length for invoice number is 99.
    Object Type

    Enter the Object name which this entry pertains to. The valid values are - Invoice, Refund, and Payment.

    To create Credit Memos with custom numbering, refer to Legal Entity-Based Custom Numbering.

    PrefixEnter a Prefix that will be applied at the beginning of the number.
    Starting Number

    Enter a digit from where you want to start the numbering. If you enter 5 and the Number Length is 3, the numbering shall begin from 005.

    Suffix

    Enter a Prefix that will be applied at the end of the number.

    Field 1Enter a Country Code which should match the Field Code you have defined in the Custom Numbering Field Mapping. You can provide value for other fields



  4. Configure Custom Numbering Configuration Setting.
    This setting is used to enable or disable the custom numbering feature and fields that are verified for applying the numbering.


    FieldDescription
    NameEnter a name for this configuration.
    Custom Numbering EnabledSelect the checkbox to enable Custom Numbering.
    Default Entry Id

    Out of various numbering formats (Custom Numbering Entries), you can specify one format that will be applicable by default for numbering invoices.
    Open a Custom Numbering Entry that you want to apply by default, copy its Id from the URL and paste it here.

    Note

    If you do not specify a Default Entry Id for numbering and Country on the Invoice does not match with any of the entries, Invoice will not be approved. You will see the following error on Invoice:

    Error Status: Custom Numbering Invoice Error

    Error Message: Cannot create a Custom Invoice Number because no Custom Entry was matched and there is no default.

    Field One EnabledSelect the checkbox to enable Field One on the Custom Numbering Entry. When enabled, the value of Field One on the Entry will be matched with the value of Field Code on Custom Numbering Field Mapping.
    Object TypeEnter the Object name which this setting pertains to. The valid values are - Invoice, Credit Memo, Refund and Payment.



  5. Add a new field Invoice Serial Number on the Invoice object by Editing the Layout.
     

Note

In case you do not see a custom number on the Invoice in spite of the performing above mentioned configurations, check out Error Status and Error Message fields on the Invoice to know what went wrong.