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:
- Create ClickLink rules as described in scenario A. See Scenario A Creating a Target Document from a Source Document.
- Ensure that Sync Enabled is selected in the ClickLink Settings custom setting.
- On the Sales Invoice object add a lookup field that points back to the Work Order header object.
- 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.
- On the Sales Invoice Line Item object, add a lookup field that points back to the Work Order Line Item object.
- 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.
- Create a checkbox field on the Sales Invoice object called IsSyncing__c.
- 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)
. - 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.
- Complete the fields in the Synchronization Setup section of the Work Order to Sales Invoice rule:
- 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.
- Enter IsSyncing__c in the Target Object Sync Active Field.
- 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
. - 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.
- Repeat the last step for the Work Order Line to Sales Invoice Line rule.
- In the Work Order to Sales Invoice rule, select the Source Sync checkbox in each mapping that is to be synchronized.
- Repeat the last step for the Work Order Line to Sales Invoice Line rule.
- 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(); }
- 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(); }
- 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(); }
- 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:
- Create a sales invoice from a work order using the Create Invoice button that you created in Scenario A.
- If you did not create a literal mapping as we recommended in step 9, on the sales invoice, select IsSyncing.
- In each sales invoice line item that is created, check that the value of the Is Syncing field is 1.00.
- Edit the work order related lists so that you can view the sales invoice and sales invoice line items.
- Edit the description field on the work order that you created the sales invoice from and click Save.
- Check that the description has updated in the related sales invoice.