(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 firstname.lastname@example.org.
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.
The screen has five main sections.
Contains the logical operator, condition, and action components.
Contains all the attributes for the specific entity/member type as well as any explicit hierarchy (consolidated) attributes.
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.
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.
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:
InHouseManufacture is equal to Y
DaysToManufacture must be between 1 and 10
- In Master Data Manager, click System Administration.
- From the menu bar, point to Manage and click Business Rules.
- On the Business Rule Maintenance page, from the Model list, select the Product model.
- From the Entity list, select the Product entity.
- From the Member Type list, select the Leaf member type.
- From the Attribute list, leave the default of All.
- Click Add business rule.
- Click Edit selected business rule to open the Business Rule Designer.
- In the Components pane, expand the Conditions node.
- 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.
- In the Entity-Specific Attributes pane, click the “InHouseManufacture” attribute and drag it to the Edit Condition pane’s Select attribute label.
- In the Edit Condition pane, enter Y in the Attribute value field.
- In the Edit Condition pane, click Save. The condition will be displayed.
- In the Components pane, expand the Actions node.
- Click the “must be between” condition and drag it to the THEN pane’s Action label.
- In the Entity-Specific Attributes pane, click the “DaysToManufacture” attribute and drag it to the Edit Action pane’s Select attribute label.
- 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).
- In the Edit Action pane, click Save. The action will be displayed.
- Click Back to return to the Business Rule Maintenance page.
- 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.
- Click Publish Business Rules
- 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.
- Go back to the home page.
- Select the Product model and a version.
- Select Explorer.
- On the Explorer page click the Edit button.
- Select Edit Member from the popup menu to edit a member that has InhouseManufacture = Y.
- Ensure the Supply Chain tab is active.
- In the Attributes section click the Edit button.
- Change the “DaysToManufacture” to 11.
- 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.
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.