Scenario A Creating a Target Document from a Source Document

In this scenario a ClickLink rule is created to generate a target record from a source record. The source and target records have child records.

Problem

You are a sales clerk and want to turn a work order into a sales invoice when the work order has been flagged as "To Invoice". When the sales invoice has been created, you want the work order to be marked "Invoiced". You also want the new sales invoice to be linked to the work order.

Solution

Create ClickLink rules to map the fields on the work order and work order line items onto a sales invoice and the sales invoice line items. In this scenario, these fields in the work order object will be mapped to the sales invoice object using a master level ClickLink rule:

Recommended Header-Level Mappings
Source in Work Order Object Source Field Data Type Target Field in Sales Invoice
Account Lookup to Account Account
Date Date Invoice Date
Summary Description Text Invoice Description
Id   Work Order

These fields in the sales order line item object will be mapped to the sales invoice line item object using a detail level ClickLink rule:

Recommended Line-Level Mappings
Source in Work Order Line Source Field Data Type Target in Sales Invoice Line Item
Service Code Lookup(Product) Product Name
Hours Number(4, 0) Quantity
Rate Currency(5, 2) Unit Price
Note:

This scenario assumes that Accounting is installed, a work order and a work order line item object already exist in the org with a master-detail relationship. If these do not exist on your org, you must create the work order and work order line item objects yourself.

To create the solution using ClickLink:

  1. If the fields described previously do not exist in the Work Order and Work Order Line Item objects create them.
  2. Add these custom fields of type Checkbox to the Work Order object with a Default Value of Unchecked:
    • To Invoice
    • Invoiced.
  3. Create the master level ClickLink rule Convert Work Order to Sales Invoice. For instance:
    Recommended Values for the Convert Work Order to Sales Invoice ClickLink Rule
    ItemValue
    ClickLink Rule NameConvert Work Order to Sales Invoice
    Source ObjectWork_Order__c
    Source Object Name FieldName
    Source Object Processed FieldInvoiced__c
    Source Object Process FieldTo_Invoice__c
    Target Objectc2g__codaInvoice__c
    Target Object Name FieldName
  4. Create the ClickLink mappings for the rule you created in the previous step:
    Recommended Mappings for the Convert Work Order to Sales Invoice ClickLink Rule
    Target Record Based OnMapping TypeMapping LiteralSource FieldTarget Field
    Source RecordSource Field Account__cc2g__Account__c
    Source RecordSource Field Date__cc2g__InvoiceDate__c
    Source RecordSource Field Summary_Description__cc2g__InvoiceDescription__c
    Source RecordSource Field WorkOrder__cId
    Source RecordLiteralFalse ffbilling__CopyAccountValues__c
  5. Create the detail level ClickLink rule to convert work order line items to sales invoice line items:
    Recommended Values for the Convert Work Order Line to Sales Invoice Line ClickLink Rule
    ItemValue
    ClickLink Rule NameConvert Work Order Line to Sales Invoice Line
    Source ObjectWO_Detail__c
    Source Object Name FieldName
    Target Objectc2g__codaInvoiceLineItem__c
    Target Object Name FieldName
  6. Create the following ClickLink mappings for the rule you created in the previous step:
    Recommended Mappings for the Convert Work Order Line to Sales Invoice Line ClickLink Rule
    Target Record Based OnMapping TypeMapping LiteralSource FieldTarget Field
    Source RecordSource Field Service_Code__cc2g__Product__c
    Source RecordLiteralFalse ffbilling__DeriveUnitPriceFromProduct__c
    Source RecordSource Field Hours__cc2g__Quantity__c
    Source RecordSource Field Rate__cc2g__UnitPrice__c
  7. In the master level ClickLink rule, create a ClickLink relationship to relate the master level ClickLink rule to the detail level ClickLink rule:
    Recommended Relationship for the Convert Work Order to Sales Invoice ClickLink Rule
    Master ClickLink RuleDetail ClickLink RuleDescriptionSource Relationship Name Target Relationship Field
    Convert Work Order to Sales InvoiceConvert Work Order Line to Sales Invoice LineLink Work Order to Sales InvoiceWork_Order_Details__rc2g__Invoice__c
    Note:

    The Source Relationship Name is the Child Relationship Name of the Master-Detail Lookup field on the detail source object suffixed with __r. For instance, in this example, the Work Order Line Item object contains a Work Order field, which is a Master-Detail Relationship with the Work Order object.

  8. Create Visualforce pages to create the sales invoice records. For instance, you can use this Visualforce markup to create a single record from the work order details.

    <apex:page standardController="Work_Order__c" extensions="ffirule.IntegrationRuleEngine" action="{!convert}"> <ffirule:IntegrationRule engine="{!engine}"/></apex:page>

    You can use this Visualforce markup to create multiple records from a work order list view.

    <apex:page standardController="Work_Order__c" extensions="ffirule.IntegrationRuleEngine" action="{!convert}" recordSetVar="records"> <ffirule:IntegrationRule engine="{!engine}"/></apex:page>

  9. In the in the Convert Work Order to Sales Invoice rule, create ClickLink buttons for the Visualforce pages you created in the previous step.
  10. In the Work Order custom object create a custom button and a custom link to access the Visualforce pages.
  11. Add the custom button to the Work Order page layout and the custom link to the Work Orders List View.

To test the ClickLink rule:

  1. Open a work order.
  2. Select the To Invoice checkbox and save the change.
  3. Click the Create Invoice button you created earlier.