Define Schema

  • Updated

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.

  1. Open irAuthor by selecting it from the Start Menu.
    ri_44.png
  2. Create a new rule application by clicking on the new rule application link on the start page, or by selecting File --> New
    ri_45.png
  3. It will automatically navigate you to the Settings screen. Rename the rule application from "NewRuleApplication" to "CustomerInvoice"
    ri_46.png
  4. 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"
    ri_47.png
  5. Add another entity by clicking the Add Entity button
    ri_48.png
  6. Rename that entity to "LineItem"
    ri_49.png
  7. Add a field to the Invoice entity by right clicking on Invoice in the left-hand navigation pane and select Add -> Field
    ri_50.png
  8. Rename the field from "Field1" to "CustID" and change the data type from text to integer
    ri_51.png
  9. 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
  10. Add another field to the Invoice entity. Rename the field to "SubTotal" and change the data type to Decimal
  11. Add a calculation to the Invoice entity
    ri_52.png
  12. Rename the calculation to "Tax", change the data type to Decimal, and set the expression to .07 * SubTotal
    ri_53.png
  13. 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
  14. Add a collection to the Invoice entity by right clicking on Invoice and select Add -> Collection
    ri_54.png
  15. 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
    ri_55.png
  16. Add a field, but this time, add it to the LineItem entity. Rename it to "ProductID". Set the data type to integer
  17. Add a field to the LineItem entity. Rename it to "ProductName". Set the data type to text
  18. Add a field to the LineItem entity. Rename it to "Quantity". Set the data type to integer
  19. Add a field to the LineItem entity. Rename it to "UnitPrice". Set the data type to Decimal.
  20. Add a calculation to the LineItem entity. Rename it to "LineItemTotal". Set the data type to Decimal. Set the expression to Quantity * UnitPrice
  21. Right click on SubTotal (in the Invoice entity), select Convert To -> Calculation. Set the expression to Sum(LineItems, LineItemTotal)
    ri_56.png
  22. 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
    ri_57.png

At this point, your Entities (schema) in the left-hand navigation pane should look like this:

ri_58.png

Now, you can move onto the next step, where you will Set Up Data Tables

 

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.