(this post was contributed by Brian Barnett, Senior Software Engineer on the MDS team)

This post is a first in a series that will explore what you can do with SQL Server 2008 R2 Master Data Services (MDS) business rules. It will introduce business rule creation and publishing. Here are some of the topics we will be covering in the future:

  • Using business rules to enable human workflow via email notifications
  • Creating and initiating a SharePoint workflow from MDS business rules
  • Using different types of conditions and actions
  • Using complex conditions
  • Using business rules to propagate attribute changes down a hierarchy
  • Getting creative with business rules.
  • What is happening under the covers when you publish and run business rules

If there are other business rule topics you are interested in please drop us a line at mdsblog@microsoft.com.

What are Business Rules?

The ability to validate master data against a variety of rules and conditions is a key component to any best-practice master data management strategy. In MDS, business rules are used to enforce data integrity and help ensure completeness and accuracy of the master data.

Business rules are If/Then statements that can be created in the Master Data Manager user interface (UI) or the WCF API. If an attribute value meets a specified condition, then an action is taken. Possible actions include setting a default value, changing a value, performing attribute validation, or initiating a SharePoint workflow.

To use business rules, you must first create and publish your rules, then validate your data against the published rules. An administrator can validate an entire version of a model at one time. Other users can validate subsets of data against business rules.

If an attribute value doesn’t pass business rule validation, the value can still be saved. Validation issues are displayed in the UI, and a version cannot be committed until all attributes pass business rule validation.

Business Rule Designer

In Master Data Manager, the Business Rule Designer is where you create and edit business rules. Drag and drop plays a key role in creation and editing of business rules, as shown below.

Business Rule Designer

The screen has five main sections.

Section Description

Components

Contains the logical operator, condition, and action components.

Entity-Specific Attributes

Contains all the attributes for the specific entity/member type as well as any explicit hierarchy (consolidated) attributes.

IF

Contains the conditions for which the action clause of the rule should be performed. You drag logical operators and conditions to this section. You can use the logical operators “AND” and “OR” to create combinations of conditions. All rules must have at least one logical operator. If no logical operator exists when you drag a condition component, an “AND” logical operator will automatically be added.

A condition is a Boolean (true or false) expression that is applied to an entity attribute. If the condition is true, the actions for the rule are performed.

A business rule does not require a condition. If no condition is specified, the actions for the rule are applied to all members.

THEN

Contains the actions that should be performed when the IF conditions are satisfied. You drag actions to this section.

An action is the consequence of a condition evaluation. If a specific condition is true, the action is initiated. You can also create a rule that initiates an action without a condition. In this case, the rule is applied to all members.

Edit

When you select a condition component in the IF section or an action component in the THEN section, the Edit section will display the individual condition or action component for editing. You drag attributes to this section as well as select and enter values.

Simple Rule Example

The following steps will show you how to create a simple validation business rule using the sample Product model. Let’s say your business manager has indicated that any product manufactured in-house must have a fabrication time of between 1 and 10 days. So, in MDS we will create this rule:

IF

    InHouseManufacture is equal to Y

THEN

    DaysToManufacture must be between 1 and 10

  1. In Master Data Manager, click System Administration.
  2. From the menu bar, point to Manage and click Business Rules.
  3. On the Business Rule Maintenance page, from the Model list, select the Product model.
  4. From the Entity list, select the Product entity.
  5. From the Member Type list, select the Leaf member type.
  6. From the Attribute list, leave the default of All.
  7. Click Add business rule.
  8. Click Edit selected business rule to open the Business Rule Designer.
  9. In the Components pane, expand the Conditions node.
  10. Click the “is equal to” condition and drag it to the IF pane's Conditions label. Notice that an “AND” logical operator is automatically added for you. If you need to start out with an “OR” then make sure you drag it over first.
  11. In the Entity-Specific Attributes pane, click the “InHouseManufacture” attribute and drag it to the Edit Condition pane's Select attribute label.
  12. In the Edit Condition pane, enter Y in the Attribute value field.
  13. In the Edit Condition pane, click Save. The condition will be displayed.
  14. In the Components pane, expand the Actions node.
  15. Click the “must be between” condition and drag it to the THEN pane's Action label.
  16. In the Entity-Specific Attributes pane, click the “DaysToManufacture” attribute and drag it to the Edit Action pane's Select attribute label.
  17. In the Edit Action pane, enter 1 in the “must be between” Attribute value field and 10 in the “and” Attribute value (as shown above).
  18. In the Edit Action pane, click Save. The action will be displayed.
  19. Click Back to return to the Business Rule Maintenance page.
  20. Optionally, on the Business Rules Maintenance page, for the row that contains your business rule, double-click a cell in the Name and Description columns to update the value.
  21. Click Publish Business Rules
  22. On the confirmation dialog box, click OK. The rule’s status will change to Active.

Try it out

Now that the rule is published you are ready to try it out.

  1. Go back to the home page.
  2. Select the Product model and a version.
  3. Select Explorer.
  4. On the Explorer page click the Edit button.
  5. Select Edit Member from the popup menu to edit a member that has InhouseManufacture = Y.
  6. Ensure the Supply Chain tab is active.
  7. In the Attributes section click the Edit button.
  8. Change the “DaysToManufacture” to 11.
  9. Click Save.

Because the updated value is outside the allowable DaysToManufacture range, a validation issue is created and displayed at the bottom of the screen showing the value violates the business rule we entered and published.

image

This was a simple example to get you started but you can see where we could add several more rules with more complex conditions to ensure DaysToManufacture is valid for a wide variety of product lines.

In the next Business Rules post, we will look at more advanced business rule capabilities by using business rules to enable human workflow via email notifications.