Skip to content

Best Practice: JustOn for Field Service

JustOn for Field Service integrates JustOn Billing & Invoice Management with Field Service Lightning, the onsite support software from Salesforce. It retrieves service items and time data tracked by service staff from Field Service, and then generates invoices based on this data applying JustOn's usage data billing.

Solution Outline

In broad strokes, the solution works as follows:

(1) Field Service and JustOn are installed in your org.

(2) You have set up the billing plan creation based on

  • service contract and service contract line item as a recurring item, and
  • a master subscription with a transactional item to hold the usage data retrieved from products consumed and time sheet entries.

(3) You create a new service contract for an account. This triggers JustOn to generate a new billing plan for this account that includes a recurring item for the service contract line items and a transactional item for the usage data.

(4) Your service staff renders some service for the account, and records the service usage in products consumed and time sheet entries.

(5) Upon invoice generation, JustOn itemizes the saved usage data, matches it against the transactional subscription item and evaluates the provided quantity information, calculating the item's subtotal. The recurring item for the service contract line item is invoiced as set up with the service contract for the current account.

field_service
Integrating automatic billing plan creation and usage data billing in Field Service Lightning

Integrating automatic billing plan creation and usage data billing in Field Service Lightning involves at least the configuration tasks as listed below.

To set up the automatic billing plan creation, you combine subscription building from objects in a parent-child relationship (service contract and service contract line item) with a master subscription:

To set up the usage data billing:

Info

Once set up as outlined, JustOn automatically

  • generates an account-specific billing plan when a user creates a service contract for an account
  • itemizes the usage data as tracked by service staff and evaluates the consumption
  • generates the invoice based on the billing plan, including both the determined service usage and the (recurring) service contract line item

Configuring Service Contract and Service Contract Line Item

Both the Service Contract object and the Service Contract Line Item object require a number of ON fields to hold the information that is necessary for the automatic billing plan generation.

To configure the Service Contract object:

  1. Navigate to the fields list of the Service Contract object.
  2. Create the following new fields.

    API Name Required Data Type Value
    ON_Account Formula (Text) AccountId (Salesforce account ID)
    ON_Subscription Lookup (Billing Plan) Related to: Subscription
    ON_MasterSubscription Formula (Text) MASTER
    ON_Status Formula (Text) Active
    ON_CurrencyIsoCode Formula (Text) TEXT(CurrencyIsoCode)
    ON_SubscriptionBuildError Text(255)
    ON_UpdateSubscription Checkbox Default Value: Unchecked
    ON_LastSubscriptionUpdate
    Date/Time
    ON_StartDate Formula (Date) StartDate
    ON_EndDate Formula (Date) EndDate
    ON_Mapping Text Area(255)

To configure the Service Contract Line Item object:

  1. Navigate to the fields list of the Service Contract Line Item object.
  2. Create the following new fields.

    Field API Name Required Data Type Value
    ON_Title Formula (Text) PricebookEntry.Product2.Name
    ON_OrderNo Formula (Text) PricebookEntry.Product2.ProductCode
    ON_ProductGroup Formula (Text) PricebookEntry.Product2.Family
    ON_Sequence Formula (Number) VALUE(LineItemNumber)
    ON_Description Formula (Text) Asset.Name
    ON_StartDate Formula (Date) StartDate
    ON_EndDate Formula (Date) EndDate
    ON_Quantity Formula (Number) Quantity
    ON_Price Formula (Currency) IF(ON_BillingType__c='Recurring',UnitPrice/12,UnitPrice)
    ON_BillingType Formula (Text) IF(ISBLANK(TEXT(PricebookEntry.Product2.SBQQ__SubscriptionType__c)),'One-Time','Recurring')

Info

Depending on your use case and its requirements, you can add more fields to have them copied to the generated subscriptions. For details, see ON Fields on Objects.

Creating Master Subscription and Items

Basically, a master subscription is a usual subscription that is not assigned to an account. That is, you just create a subscription, add all items and define any required conditions, but do not assign it to an account.

As the transactions are to be matched with subscription items for the invoice generation, you must prepare the master "target" subscription and the corresponding transactional items:

  1. Create the master subscription as required.

    Do not assign the subscription to an account. The field Account may be set as required, however. In this case, navigate to the Subscription page layout, open the field properties for the Account field and deselect the Required checkbox.

    The subscription name will be used as an input parameter when configuring the target object. JustOn recommends to prefix the master subscription name with MASTER.

    For details, see Creating Subscriptions.

  2. Add the items to the subscription as required.

    Following the solution approach, you create two items:

    • Item 1 to match tracked Product Consumed records
    • Item 2 to match tracked Time Sheet Entry records.

    The mandatory parameters include:

    Field Value Item 1
    Title Used Material
    Billing Type Transactional
    OrderNo PROD
    Field Value Item 2
    Title Worked Time
    Billing Type Transactional
    OrderNo TIME

    For details, see Adding Items.

Note

Make sure that each item's value of the OrderNo field matches one of the possible values of the usage data objects' ON_OrderNo field (see Configuring Product Consumed and Time Sheet Entry).

Creating Subscription Build Filter

To define which objects and records to include in the subscription build process, you create a new custom filter.

  1. In Setup, open Custom Settings.

    In Salesforce Lightning, navigate to Custom Code > Custom Settings.

    In Salesforce Classic, navigate to Develop > Custom Settings.

  2. Click Manage in the row of Filters.

  3. Create the following filter for the subscription build.

    Field Value
    Name Subscription Build Filter
    Target ServiceContract
    Child Relation ContractLineItems
    Use Case Subscription Builder
    Condition Status = 'Activated'

    For help about creating filters, see Filters.

Scheduling Subscription Build Job

You can set up a job in order to have subscriptions built automatically on a regular basis.

The subscription build job does not require additional parameters. That is, you can set up the job directly for the corresponding batch chain SubscriptionBuilderChain. For details, see Scheduling Concepts.

To schedule the subscription build batch chain, you can use either JustOn's Scheduled Jobs page or Salesforce's Schedule Apex functionality. For details, see Scheduling a Job.

Via JustOn's Scheduled Jobs page:

  1. Open the Scheduled Jobs page.

    Use the following URL https://login.salesforce.com/apex/ONB2__JobsSetup, or, if you are already logged in, append apex/apex/ONB2__JobsSetup to your org's domain name.

    As of JustOn 2.52, you can access the Scheduled Jobs page via the JustOn configuration app (App Launcher > JustOn Configuration > Jobs Setup).

  2. From the Apex Job drop-down list, select Subscription Builder Job.

    The Job Name field is automatically set to SubscriptionBuilderChain.

  3. From the Start Time drop-down list, select the preferred execution time.

  4. Optionally, edit the displayed cron expression to adjust the execution time.
  5. Click Schedule.

    This sets up the subscription build to be executed at the specified time.

Info

From the Scheduled Jobs page, you can also run the batch chain immediately.

Via Salesforce's Schedule Apex functionality:

  1. In Setup, open Apex Classes.

    In Salesforce Lightning, navigate to Custom Code > Apex Classes.

    In Salesforce Classic, navigate to Develop > Apex Classes.

  2. Click Schedule Apex on top of the list.

  3. Specify the details as required.

    • Job Name: SubscriptionBuilderChain
    • Apex Class: ScheduledBatchChain
    • Frequency: Weekly or Monthly (with an according weekday or day of month setting)
    • Start
    • End
    • Preferred Start Time
  4. Click Save.

    This sets up the subscription build to be executed at the specified time.

For more details about job scheduling, see Scheduling a Job in the JustOn documentation and Schedule Apex in the Salesforce Help.

You can also invoke the subscription builder using the following code in the Force.com Developer Console (see Developer Console Functionality in the Salesforce Help):

new ONB2.ChainRunner()
.execute(
    new ONB2.ChainFactory().getByName('SubscriptionBuilderChain')
);

Configuring Product Consumed and Time Sheet Entry

JustOn's transaction builder requires a number of ON fields (controlling fields and data fields) on the objects that hold usage data. Following the solution approach, you configure the Product Consumed and Time Sheet Entry objects accordingly.

To add the required fields to the Product Consumed object:

  1. Navigate to the fields list of the Product Consumed object.
  2. Create the following new fields.

    API Name Data Type Value
    ON_Account Formula (Text) WorkOrder.AccountId
    ON_AddToCsv Checkbox Default Value: Unchecked
    ON_AddToTransactionTable Checkbox Default Value: Unchecked
    ON_Date Formula (Date) WorkOrder.EndDate
    ON_Invoice Lookup(Invoice)
    ON_LastError Text(255)
    ON_OrderNo Formula (Text) PROD
    ON_Price Formula (Currency) UnitPrice
    ON_Quantity Formula (Number) ABS(QuantityConsumed)
    ON_Subscription Lookup(Billing Plan)
    ON_Title Formula (Text) PricebookEntry.Product2.Name
    ON_Type Formula (Text) Transaction

To add the required fields to the Time Sheet Entry object:

  1. Navigate to the fields list of the Time Sheet Entry object.
  2. Create the following new fields.

    API Name Data Type Value
    ON_Account Formula (Text) CASESAFEID(WorkOrder.AccountId)
    ON_AddToCsv Checkbox Default Value: Unchecked
    ON_AddToTransactionTable Checkbox Default Value: Unchecked
    ON_Date Formula (Date) DATEVALUE(WorkOrder.EndDate)
    ON_Invoice Lookup(Invoice)
    ON_LastError Text(255)
    ON_OrderNo Formula (Text) TIME
    ON_Quantity Formula (Number) DurationInMinutes/60
    ON_Subscription Lookup(Billing Plan)
    ON_Type Formula (Text) Transaction

Creating Transaction Filter

To define which objects and records to include in the transaction build process, you create custom filters.

  1. In Setup, open Custom Settings.

    In Salesforce Lightning, navigate to Custom Code > Custom Settings.

    In Salesforce Classic, navigate to Develop > Custom Settings.

  2. Click Manage in the row of Filters.

  3. Create the following filters for the transaction build.

    Field Value
    Name Material
    Target ProductConsumed
    Use Case Continuous
    Condition WorkOrder.Status='Completed'
    Field Value
    Name Time
    Target TimeSheetEntry
    Use Case Continuous
    Condition WorkOrder.Status='Completed'

    For help about creating filters, see Filters.

Setting Up Continuous Invoice Run

To set up a continuous invoice run, you schedule a parameterized invoice run with the corresponding transaction filter (use case Continuous/Continuous Daily) added as a parameter.

Setting up a parameterized invoice run involves two steps:

  • Defining parameters for the batch chain
  • Scheduling the batch chain

Configuring Batch Chain Parameters

  1. In Setup, open Custom Settings.

    In Salesforce Lightning, navigate to Custom Code > Custom Settings.

    In Salesforce Classic, navigate to Develop > Custom Settings.

  2. Click Manage in the row of Batch Parameters.

  3. Click New.
  4. Specify the details as required.

    • Name: Must match the Job Name to be set when scheduling the job
    • Batch Chain: InvoiceRunChain
    • Parameter 1: TransactionFilters = Material,Time

      Make sure to set the transaction filter names as defined in Creating Transaction Filter.

      You can set additional parameters as required.

  5. Click Save.

Scheduling Batch Chain

To schedule the batch chain, you can use either JustOn's Scheduled Jobs page or Salesforce's Schedule Apex functionality. For details, see Scheduling a Job.

Via JustOn's Scheduled Jobs page:

  1. Open the Scheduled Jobs page.

    Use the following URL https://login.salesforce.com/apex/ONB2__JobsSetup, or, if you are already logged in, append apex/apex/ONB2__JobsSetup to your org's domain name.

    As of JustOn 2.52, you can access the Scheduled Jobs page via the JustOn configuration app (App Launcher > JustOn Configuration > Jobs Setup).

  2. From the Apex Job drop-down list, select Batch Chain Job.

  3. In the Job Name field, specify the name of the batch parameters setting created before.
  4. From the Start Time drop-down list, select the preferred execution time.
  5. Click Schedule.

    This sets up the invoice run to be executed on a regular basis at the specified time with the additional parameters set.

Info

From the Scheduled Jobs page, you can also run the batch chain immediately.

Via Salesforce's Schedule Apex functionality:

  1. In Setup, open Apex Classes.

    In Salesforce Lightning, navigate to Custom Code > Apex Classes.

    In Salesforce Classic, navigate to Develop > Apex Classes.

  2. Click Schedule Apex on top of the list.

  3. Specify the details as required.

    • Job Name: The name of the batch parameters setting created before
    • Apex Class: ScheduledBatchChain
    • Frequency
    • Start
    • End
    • Preferred Start Time
  4. Click Save.

    This sets up the invoice run to be executed on a regular basis at the specified time with the additional parameters set.

For more details about job scheduling, see Scheduling a Job in the JustOn documentation and Schedule Apex in the Salesforce Help.