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.
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:
- Adding required fields to service contract and service contract line item
- Creating a master subscription with transactional items
- Creating a subscription build filter
- Scheduling a job to build subscriptions
To set up the usage data billing:
- Adding required fields to product consumed and time sheet entry
- Creating a transaction filter
- Setting up the continuous invoice run
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
Setting Up Billing Plan Creation
Setting up the automatic billing plan creation involves
- Adding required fields to service contract and service contract line item
- Creating a master subscription with transactional items
- Creating a subscription build filter
- Scheduling a job to build subscriptions
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:
- Navigate to the fields list of the Service Contract object.
-
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 (Long)
To configure the Service Contract Line Item object:
- Navigate to the fields list of the Service Contract Line Item object.
-
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:
-
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 theAccount
field and deselect theRequired
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.
-
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.
-
Click to enter Setup, then open Custom Settings.
In Salesforce Lightning, navigate to Custom Code > Custom Settings.
In Salesforce Classic, navigate to Develop > Custom Settings.
-
Click Manage in the row of Filters.
-
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.
Note
The subscription build job always processes all available subscription build filters. Be aware that this may, consequently, produce multiple subscriptions for an account.
Via JustOn's Scheduled Jobs page:
-
Open the Scheduled Jobs page.
Use the following URL
https://login.salesforce.com/apex/ONB2__JobsSetup
, or, if you are already logged in, appendapex/ONB2__JobsSetup
to your org's domain name.You can access the Scheduled Jobs page via the JustOn configuration app ( > JustOn Configuration > Jobs Setup).
-
From the
Apex Job
drop-down list, selectSubscription Builder Job
.The
Job Name
field is automatically set toSubscriptionBuilderChain
. -
From the
Start Time
drop-down list, select the preferred execution time. - Optionally, edit the displayed cron expression to adjust the execution time.
-
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:
-
Click to enter Setup, then open Apex Classes.
In Salesforce Lightning, navigate to Custom Code > Apex Classes.
In Salesforce Classic, navigate to Develop > Apex Classes.
-
Click Schedule Apex on top of the list.
-
Specify the details as required.
- Job Name:
SubscriptionBuilderChain
- Apex Class:
ScheduledBatchChain
- Frequency:
Weekly
orMonthly
(with an according weekday or day of month setting) - Start
- End
- Preferred Start Time
- Job Name:
-
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 Salesforce Developer Console:
new ONB2.ChainRunner()
.execute(
new ONB2.ChainFactory().getByName('SubscriptionBuilderChain')
);
Setting Up Usage Data Billing
Setting up the usage data billing involves
- Adding required fields to product consumed and time sheet entry
- Creating a transaction filter
- Setting up the continuous invoice run
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:
- Navigate to the fields list of the Product Consumed object.
-
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:
- Navigate to the fields list of the Time Sheet Entry object.
-
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.
-
Click to enter Setup, then open Custom Settings.
In Salesforce Lightning, navigate to Custom Code > Custom Settings.
In Salesforce Classic, navigate to Develop > Custom Settings.
-
Click Manage in the row of Filters.
-
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
-
Click to enter Setup, then open Custom Settings.
In Salesforce Lightning, navigate to Custom Code > Custom Settings.
In Salesforce Classic, navigate to Develop > Custom Settings.
-
Click Manage in the row of Batch Parameters.
- Click New.
-
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.
- Name: Must match the
-
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:
-
Open the Scheduled Jobs page.
Use the following URL
https://login.salesforce.com/apex/ONB2__JobsSetup
, or, if you are already logged in, appendapex/ONB2__JobsSetup
to your org's domain name.You can access the Scheduled Jobs page via the JustOn configuration app ( > JustOn Configuration > Jobs Setup).
-
From the
Apex Job
drop-down list, selectBatch Chain Job
. - In the
Job Name
field, specify the name of the batch parameters setting created before. -
From the
Start Time
drop-down list, select the preferred execution time.Your business may require to schedule multiple invoice runs. In order to prevent concurrent access to records or batch job limitations, they should, however, not run in parallel. Therefore, JustOn recommends to involve a certain time delay between the scheduled invoice runs – for example, one at 00:00, the next at 01:00, and so on. The interval may vary depending on the amount of records to be processed.
-
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:
-
Click to enter Setup, then open Apex Classes.
In Salesforce Lightning, navigate to Custom Code > Apex Classes.
In Salesforce Classic, navigate to Develop > Apex Classes.
-
Click Schedule Apex on top of the list.
-
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
Your business may require to schedule multiple invoice runs. In order to prevent concurrent access to records or batch job limitations, they should, however, not run in parallel. Therefore, JustOn recommends to involve a certain time delay between the scheduled invoice runs – for example, one at 00:00, the next at 01:00, and so on. The interval may vary depending on the amount of records to be processed.
-
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.