This example shows how a Ruleset can be configured to use different actions, conditions, and variables. There are many different ways to create rules to achieve a single transformation goal. Because of the many options Clarify provides, you may - and likely will - find other ways to create rules that accomplish your transformation needs.
A typical scenario: Flat File to Flat File Ruleset
- Composite Rules
- Conditions applied to Rules
- An Action (Code Table) used as a Rule
- An Action (Business Process) used as a Rule
Example: Composite Rules
Expand each Schema node so you can see the Records it contains. With no rules created, the Ruleset looks like this:
To create Composite Rules, drag the source record nodes to their corresponding target record nodes. Start with Record Group: FullOrder to Record Group: PurchaseOrder, then Record: Order to Record: PO.
After creating your second Composite Rule, you must click to select the For each Record Group: FullOrder create a new Record Group: Purchase Order Composite Rule when creating Composite Rules for the other records within it (instead of nested in each other).
Notice as you create each one, the Rule appears in the Rules section. Each one is a different "For each Record create a new Record" rule, instructing Clarify how to relate each record and when to start a new one.
Notice the order of records is different in each Schema. Lines and LI correspond and Notes and SI (Special Instructions) don't appear in the same order. As long as you drag the data to the appropriate node, the data will appear as your trading partner wants it.
Hard-coding an Initial Value
The first field of each record contains an ID that identifies the fields in the record. It's different in our file than in our trading partner's.
|Our first field code||Their first field code|
There are multiple ways to accomplish getting the correct value into their file.
Altering a Move Rule
Under Rules, click on For each Record: Order create a new Record: PO Composite Rule to select it. In the Schemas, drag our source OrderID node onto their target POid node.
Under Rules the Rule Move: [From=OrderID] -> [POid] appears. In the Properties view's Rule section, notice the Rule is moving the Inputs value OrderID to the Outputs value POid.
Under Inputs, click on the Value OrderID. Type POid and press Enter. An icon appears next to the new value, indicating it is a hard-coded initial value.
In the Rules section, the Rule also changes to Move: [From=POid] -> [POid].
Hard-coding an initial value in a variable
Another way to hard-code an initial value is to create a variable. We'll use that method for the second code, CI.
In the Variables panel, click the Add Variables button. The Create a New Variable window appears. In the Name field, type TheirCompanyId. Leave the Type as String and in the Valuefield, type CI. Press OK.
In the Variables panel, our new variable TheirCompanyID appears.
In the Rules section, click on the Composite Rule For each Record: Company create a new Record: CI to select it. Drag the TheirCompanyID to the target Schema node CIid.
Use a Rule with a Move Action on any source field whose data can go directly into the target field.
With the second Composite Rule (For each Record: Order create a new Record: PO) selected, drag the source Schema OrderNumber node onto the target Schema POcode field. Then drag the source Schema OrderDate node onto the POdate node.
Notice in the Rules section, the Rules appear as children of the Composite Rule.
With its move Rules defined under their respective Composite Rules, the Ruleset looks like this:
If the shipping address is the same as the billing address, we want the phrase "Same as shipping address" in the BTadd1 field. We want all subsequent fields after it to be blank.
When the addresses are not the same...
First, we will condition the Rule to write the record normally when the addresses are different.
Click on the Composite Rule For each Record: Billing create a new Record: BT to select it. Go to the Properties view's Condition panel.
In the Actions tab's filter box, find the StringNotEquals Action (either by typing string in the filter box or looking in the string folder). Drag the StringNotEquals Action to the Conditionpanel's Condition field.
In the Inputs section, two Properties appear, stringA and stringB. From the source Schema, drag the ShipAdd1 node to stringA's value and BillAdd1 to stringB's value. This condition is complete, and this Composite Rule (and its child Rules) will only write when the addresses are different.
When the addresses are the same...
We will create another Composite Rule at the same level as the previous one. So, with the parent Composite Rule For each Record Group: FullOrder create a new Record Group: PurchaseOrder selected, click the New Composite Rule button. Then move it until it is after but at the same level as the Composite Rule we just conditioned. From the source Schema, drag the Record: Billing node to the Rule's Properties view Inputs value. From the target Schema, drag the Record: BT node to the Outputs value. In the Rules section, the Composite Rule now reads: For each Record: Billing create a new Record: BT.
In the Actions panel's filter box, find the StringEquals Action (either by typing string in the filter box or looking in the string folder). Drag the StringEquals Action to the Properties view Condition tab's Condition field.
In the Inputs section, two Properties appear, stringA and stringB. From the source Schema, drag the ShipAdd1 node to stringA's value and BillAdd1 to stringB's value.
Create a child Rule that moves a hard-coded value "Same as shipping address" in the BTadd1. To leave the rest of the BT fields blank, don't create Rules for them. This condition is complete, and this Composite Rule (and its child Rules) will only write when the addresses are the same. When it does, it will only write "Same as shipping address."
Our trading partner puts their contact representative's first name and last name in separate fields. We want it in a single field with a space between them.
With the Composite Rule For each Record: Representative create a new Record: CN selected, click the New Rule button. Type concatenate in the filter field and double-click ConcatenateWithBlankSpace.
In the Properties view's Rule tab, the Inputs section has two properties, SourceString1 and SourceString2.
From the source Schema, drag the RepFirstName node to the SourceString1's Value. Then drag the RepLastName node to the SourceString2's Value.
From the target Schema, drag the CNname node to the Outputs' Return Assignments field.
Using a Code Table as an Action
Our trading partner has different SKU codes than ours. We've created a Code Table that contains their SKU and relates it to our SKU.
With the Composite Rule For each Record:Lines create a new Record:LI selected, click the New Rule button. Type part of the code table name in the filter box, then double-click on the Code Table (in this case, its examplesTheirSKUtoOurSKUct.RulesetAction). In the Properties tab's Rule panel, the Inputs section has one property, Key1.
From the source Schema, drag the LineOurSKU node to the Inputs section's Key1 Value. From the target Schema, drag the LItheirSKU to the Outputs section's Return Assignmentssection.
Using a Business Process as an Action
For every purchase order, we want to receive an email with its total. We've created a Business Process to do this.
With the Composite Rule For each Record: Total create a new Record: TO highlighted, click the New Rule button. Type part of the Business Process name in the filter box, then double-click on the Business process (in this case, examplesEmailTotalCost.)
In the Business Process editor, we created a storage node Parameter to add as an email attachment. We called this Parameter TotalCostForEmail. When using the Business Process as a Rule, the parameter appears in the Property view's Inputs section. Drag the source Schema node TotalCost to the TotalCostForEmail's Value area.
Using a Rule once per transformation
We want to receive an email if everything went okay with this Ruleset. We only want to send one email after all orders have been processed. We have created a Business Process to do this.
Right-click on the top-most Composite Rule (in this case, For each Record Group: FullOrder create a new Record Group: PurchaseOrder). Select Add Sibling | Rule. Type part of the Business Process name in the filter box, then double-click on the Business Process (in this case, examplesEmailMeBps.bps). Since this is a generic, self-contained email composed of string literals (and nothing from the purchase orders needs to be included), we do not have to configure the Rule any further.
Please sign in to leave a comment.