Scenario E Synchronization

In this scenario a sales invoice is created from a work order. The sales invoice lines are created from the work order lines using header and detail ClickLink rules. The synchronization options are set so that if you change the values of work order fields, the changes are automatically shown in the sales invoice and sales invoice lines.

Problem

You have used ClickLink rules to create target records such as sales invoices from work orders, but the source information is likely to change after you create the sales invoices and you do not want to manually update them.

Solution

Use ClickLink synchronization to automatically update sales invoices and sales invoice lines when the work orders that they were created from are updated or deleted:

  1. Create ClickLink rules as described in scenario A. See Scenario A Creating a Target Document from a Source Document.
  2. Ensure that Sync Enabled is selected in the ClickLink Settings custom setting.
  3. On the Sales Invoice object add a lookup field that points back to the Work Order header object.
  4. In the Work Order to Sales Invoice rule, create a mapping from the Work Order Id field to the lookup field that you created in the previous step.
  5. On the Sales Invoice Line Item object, add a lookup field that points back to the Work Order Line Item object.
  6. In the Work Order Line to Sales Invoice Line rule, create a mapping from the Id field of the Work Order Line Item to the field that you created in the Sales Invoice Line Item object.
  7. Create a checkbox field on the Sales Invoice object called IsSyncing__c.
  8. On the Sales Invoice Line Item object create a formula number field called IsSyncing__c with the formula: IF( c2g__Invoice__r.IsSyncing__c , 1, 0).
  9. We recommend that you create a literal mapping in the header ClickLink rule that maps the value True to the IsSyncing__c field on the target header object. This will automatically synchronize target records with source record when they are created.
  10. Complete the fields in the Synchronization Setup section of the Work Order to Sales Invoice rule:
    1. Select Sync Enabled, see Sync Enabled for more information. If the synchronization rule is a master rule with no detail rules, select Sync Is Master, see Sync Is Master for more information.
    2. Enter IsSyncing__c in the Target Object Sync Active Field.
    3. In the Target Object Sync Control Field enter the API name of the field in the Sales Invoice object that you want to use to control when synchronization occurs. For instance, c2g__InvoiceStatus__c.
    4. In the Target Object Sync Control When field, enter a list of values that the Target Object Sync Control Field can be set to for synchronization to occur. Each value in the list must be on a separate line.
  11. Repeat the last step for the Work Order Line to Sales Invoice Line rule.
  12. In the Work Order to Sales Invoice rule, select the Source Sync checkbox in each mapping that is to be synchronized.
  13. Repeat the last step for the Work Order Line to Sales Invoice Line rule.
  14. Create the following Apex trigger in the Work Order object:

    trigger WorkOrderSyncTrigger on WorkOrder__c (after delete, after insert, after undelete, after update, before delete, before insert, before update) { ffirule.IntegrationRuleEngine.triggerHandler(); }

  15. Create the following Apex trigger in the Work Order Line Item object:

    trigger WorkOrderLineItemSyncTrigger on WorkOrderLineItem__c (after delete, after insert, after undelete, after update, before delete, before insert, before update) { ffirule.IntegrationRuleEngine.triggerHandler(); }

  16. Create the following Apex trigger in the Sales Invoice object:

    trigger SalesInvoiceSyncTrigger on c2g__codaInvoice__c (after delete, after insert, after undelete, after update, before delete, before insert, before update) { ffirule.IntegrationRuleEngine.triggerHandler(); }

  17. Create the following Apex trigger in the Sales Invoice Line Item object:

    trigger SalesInvoiceLineItemSyncTrigger on c2g__codaInvoiceLineItem__c (after delete, after insert, after undelete, after update, before delete, before insert, before update) { ffirule.IntegrationRuleEngine.triggerHandler(); }

To test synchronization:

  1. Create a sales invoice from a work order using the Create Invoice button that you created in Scenario A.
  2. If you did not create a literal mapping as we recommended in step 9, on the sales invoice, select IsSyncing.
  3. In each sales invoice line item that is created, check that the value of the Is Syncing field is 1.00.
  4. Edit the work order related lists so that you can view the sales invoice and sales invoice line items.
  5. Edit the description field on the work order that you created the sales invoice from and click Save.
  6. Check that the description has updated in the related sales invoice.