In this section you will learn how to manually define a schema. A schema is the definition of a data structure and describes the data elements and their interrelationships. In InRule, the schema is made up of Entities, Fields, Collections, and Calculations. It can either be created manually or imported from an external resource such as a database, XSD, or a .NET Assembly.
Manually defining a schema is recommended when prototyping and creating proof-of-concept. Importing from (and binding to) to an external schema will allow you to create a complete entity structure using a previously existing data structure. Utilizing an external schema is recommended when creating complex entity structures.
Note: Schema definitions should be managed and/or coordinated with the development group because it is the main “contract” between business applications and rules.
- Open irAuthor by selecting it from the Start Menu.
- Create a new rule application by clicking on the new rule application link on the start page, or by selecting File --> New
- It will automatically navigate you to the Settings screen. Rename the rule application from "NewRuleApplication" to "CustomerInvoice"
- When you create a new rule application, irAuthor will automatically start you off with an entity called "Entity1". Click on Entity1 and rename that entity to "Invoice"
- Add another entity by clicking the Add Entity button
- Rename that entity to "LineItem"
- Add a field to the Invoice entity by right clicking on Invoice in the left-hand navigation pane and select Add -> Field
- Rename the field from "Field1" to "CustID" and change the data type from text to integer
- Add another field to the Invoice entity by right clicking on Invoice and select Add -> Field. Rename the field to "CustName" and leave the data type to text
- Add another field to the Invoice entity. Rename the field to "SubTotal" and change the data type to Decimal
- Add a calculation to the Invoice entity
- Rename the calculation to "Tax", change the data type to Decimal, and set the expression to .07 * SubTotal
- Add another calculation to the Invoice entity. Rename the calculation to "Total", change the data type to Decimal, and set the expression to SubTotal + Tax
- Add a collection to the Invoice entity by right clicking on Invoice and select Add -> Collection
- Rename the collection to "LineItems", set the data type to Entity, and select LineItem as the entity that this collection will contain. Click the Parent context checkbox
- Add a field, but this time, add it to the LineItem entity. Rename it to "ProductID". Set the data type to integer
- Add a field to the LineItem entity. Rename it to "ProductName". Set the data type to text
- Add a field to the LineItem entity. Rename it to "Quantity". Set the data type to integer
- Add a field to the LineItem entity. Rename it to "UnitPrice". Set the data type to Decimal.
- Add a calculation to the LineItem entity. Rename it to "LineItemTotal". Set the data type to Decimal. Set the expression to Quantity * UnitPrice
- Right click on SubTotal (in the Invoice entity), select Convert To -> Calculation. Set the expression to Sum(LineItems, LineItemTotal)
- Save the rule application by clicking the Save button on the Quick Access Toolbar, or by selecting File->Save. It will prompt you to choose between saving to the catalog or a file. Select File and then go ahead and save the rule application to your file system
At this point, your Entities (schema) in the left-hand navigation pane should look like this:
Now, you can move onto the next step, where you will Set Up Data Tables
Comments
0 comments
Please sign in to leave a comment.