Skip to content

Invoice Import and Fix

JustOn allows for creating invoices without using JustOn's business processes (like invoice run). This is necessary, for example, when migrating data from previous systems to JustOn. In some cases, imported invoices may not be valid in some parts (for example, balance, due dates, texts, addresses) and therefore need to be fixed after the import.

Info

The invoice fixing feature is available as of JustOn 2.42.

This section

  • Specifies the required data fields for invoice imports
  • Describes the fixing process
  • Outlines the options for invoking the invoice fixing process.

Info

The invoice import is project-specific and therefore not covered with this documentation. Generally, you can use any Salesforce API to insert invoice records:

Invoice Record Data

The following fields are required to insert an invoice record:

Field Possible Values Description
Status Pre-Draft
Pre-Open
The status must be prefixed with Pre- in order to allow the import.
Pre-Draft invoices will have the status Draft after fixing.
Pre-Open invoices will have the status Open after fixing.
Name existing invoice number The invoice number of Pre-Open invoices will not be replaced.
Make sure that the invoice number is correct and unique.
Account Salesforce account ID or
External ID of the Salesforce account
An invoice must be associated with an existing account in Salesforce. If the account ID is is not available, you can use external IDs instead.
Template JustOn template ID or
External ID of the JustOn template
An invoice must be associated with an existing template. You can associate the template by its ID or by using external IDs.
Date empty or
existing date
If the date is empty, JustOn will use the current date when finalizing the invoice.
Currency ISO Code one of the active currencies, like EUR, USD This is only applicable in multi-currency organizations. If no currency is set, the system will copy the currency from the account.

All other invoice fields are optional. For information about which fields may be set during the invoice fixing process, see Imported Invoices Fix.

Invoice Line Item Record Data

The following fields are required to insert invoice line item records:

Field Possible Values Description
Invoice JustOn invoice ID or
External ID of the invoice (preferably the existing unique invoice number)
Invoice line items must be associated with an invoice record. This can be done by using the Salesforce ID of the invoice record or by using external IDs instead.
Pre- type invoice line items can only be associated with Draft/Pre-Draft/Pre-Open invoices.
Type Pre-Product
Pre-Shipping Fees
The type must be prefixed with Pre- in order to allow the import.
Pre-Product invoice line items will have the type Product after fixing.
Pre-Shipping Fees invoice line items will have the type Shipping Fees after fixing.
Title the title of the invoice line item The title is displayed on the invoice PDF and names the sold product or service.
Unit Price the price for one unit of the sold product or service The unit price is interpreted as a net value unless the invoice is marked as a gross invoice.
Quantity the sold quantity
Tax Rate the tax rate of the invoice line item
Currency ISO Code one of the active currencies, like EUR, USD This is only applicable in multi-currency organizations. If no currency is set, the system will copy the currency from the invoice.

All other invoice line item fields are optional. For information about which fields may be set during the invoice fixing process, see Imported Invoices Fix.

Imported Invoices Fix

Imported invoices in status Pre-Draft/Pre-Open and invoice line items with a Pre- type are ignored by JustOn. They need to be fixed in order to be available. With the fixing process, Pre-Draft invoices get the status Draft, Pre-Open invoices get the status Open.

Note

Imported Pre-Draft invoices are subject to the usual processes and operations for draft invoices after fixing.
Imported Pre-Open invoices are unalterable (and immediately effective) after fixing, like all finalized invoices.

The system runs the following business processes upon invoice fixing on all empty invoice fields:

Pre-Draft/Pre-Open

  • set contacts from contact roles
  • set contacts from ON fields
  • copy addresses
  • set account name
  • set tenant
  • set ISO currency code
  • set payment due
  • set payment fields (bank info)
  • copy ON fields from account
  • calculate service period
  • set balance and payment status

Pre-Open

  • set date
  • set conversion rate
  • copy and render template fields
  • render invoice line item fields

The system runs the following business processes upon invoice fixing on all empty invoice line item fields:

  • set ISO currency code
  • set gross invoice
  • set sequence
  • set factor (from the unit)
  • set discount amount
  • set order discount amount
  • set accounting fields

Calling the Import Fixing Process

JustOn provides several options for invoking the invoice fixing process after the import.

Batch Process From JustOn Invoices List View

  1. Add the button Fix Invoices to the invoices list view.
    For details, see Managing Page Layouts.
  2. Create a list filter to show only Pre-Draft/Pre-Open invoices.
  3. Use the button to fix all or the selected invoices.
    ▶ This will execute a batch process. The progress is shown in the user interface.

Info

Use this for one-time migrations during the initial setup of JustOn.

Batch Process From APEX Code

If you use APEX to create invoices, you may consider executing the batch process for a list of invoices. Please note that this cannot be called from a trigger context, because the batch is running asynchronously and cannot operate on a single invoice.

Use the following code snippet to create and execute the batch:

Set<Id> invoiceIds = new Set<Id>(); //provide the IDs of all Draft/Pre-Draft/Pre-Open invoices, which need to be fixed

new ONB2.ChainRunner().execute(
    new ONB2.ChainFactory().getForBatchNames(
        new List<String>{'BatchFixInvoices'}
    )
    .setParameters(
        new Map<String, Object>{
            'invoiceIds' => invoiceIds
        }
    )
);

Synchronous Execution From APEX Code

If the number of invoices is small (< 10) and your APEX code is guaranteed to run sequentially (no triggers, no queueables, no batch processes, no external parallelization), you may call the global API directly:

List<Id> invoiceIds = new List<Id>(); //provide the IDs of all Draft/Pre-Draft/Pre-Open invoices, which need to be fixed

ONB2.FixInvoicesApi.fromProcess(invoiceIds);

REST Endpoint Call

If you create invoices via REST, JustOn allows you to fix these invoices via REST as well. Please note that the number of invoices that can be fixed in one call should not exceed 10. You should also not call the API in parallel.

JustOn accepts an HTTP POST request at the following endpoint:

https://INSTANCE.salesforce.com/services/apexrest/ONB2/FixInvoicesApi

The body of the request must be in JSON format and contain a list of invoice IDs to be fixed:

{"invoiceIds":["id1","id2"]}

Process Configuration

It is possible to configure a process on invoices and trigger the invoice fixing process. This is useful, for example, if you create invoices from a flow or do not want to call the REST endpoint. When using a process, the number of invoices per transaction should also not exceed 10.

  1. In Setup, open Process Builder.
    In Salesforce Lightning, navigate to Process Automation > Process Builder.
    In Salesforce Classic, navigate to Create > Workflow & Approvals > Process Builder.
  2. Create the following process.
    For help about creating processes, see Create a Process in the Salesforce Help.
Option Value Description
Object Invoice The process must run on the Invoice object when a record is created or edited.
Criteria Select the conditions that meet your business requirements best.
Immediate Action Apex > Fix invoices and line items Set the IDs of the invoices to be fixed as the input parameter.