Specialized Administration > Configuring Your Windchill Environment > Business Rules > Example for Bypassing Business Rule Conflicts
  
Example for Bypassing Business Rule Conflicts
You might want to show some or all business rule failures, but not prevent the workflow from continuing or completing. Create two unique business rule sets, one in which the rules are required for continuing or completing the process and another in which failures of rules are reported but are not required to complete the process. Having two separate business rule sets allow you to configure a workflow process to call either rule set at different points in the workflow process.
The following example shows how to configure a set of rules that are required to proceed and a second set of rules that are not required. Assume that you want to check that certain attributes are filled in (in this case, Material). If the attributes are blank, the process will continue; however, the release target rule must pass.
1. Create a nonrequired business rule set for attribute checks.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRuleSet SYSTEM "standardX20.dtd">
<BusinessRuleSet>
<ObjectID><localId>wt.businessRules.BusinessRuleSet:10001</localId>
</ObjectID>

<objectContainerPath>/wt.inf.container.OrgContainer=
Demo Organization/wt.pdmlink.PDMLinkProduct=Example1TestProduct
</objectContainerPath>

<key>EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET</key>
<name>EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET</name>
<description>EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET</description>
<enabled>true</enabled>
<overridable>true</overridable>
<updateIfExists>true</updateIfExists>
</BusinessRuleSet>
2. Create an attribute rule for Material.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRule SYSTEM "standardX20.dtd">
<BusinessRule>
<ObjectID><localId>wt.businessRules.BusinessRule:10002</localId>
</ObjectID>

<objectContainerPath>/wt.inf.container.OrgContainer=
Demo Organization/wt.pdmlink.PDMLinkProduct=Example1TestProduct
</objectContainerPath>

<key>EXAMPLE1_ATTRIBUTE_RULE</key>
<selector>ATTRIBUTE_RULE</selector>
<name>Example 1 Attribute Rule</name>
<description>Example 1 Attribute Rule</description>
<enabled>true</enabled>
<updateIfExists>true</updateIfExists>
<configs>
<config name="objectType" value="com.ptc.Part"></config>
<config name="Material" value="SET"></config>
</configs>
</BusinessRule>
3. Create a link for the attribute rule and the nonrequired rule set.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRule SYSTEM "standardX20.dtd">
<BusinessRuleLink>
<ObjectID><localId>wt.businessRules.BusinessRuleLink:10003</localId>
</ObjectID>

<ruleSet><ObjectReference><localId>wt.businessRules.BusinessRuleSet:10001
</localId></ObjectReference></ruleSet>

<rule><ObjectReference><localId>wt.businessRules.BusinessRule:10002
</localId></ObjectReference></rule>
<blockNumber>1</blockNumber>
<updateIfExists>true</updateIfExists>
</BusinessRuleLink>
4. Create a required business rule set for release target rule.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRuleSet SYSTEM "standardX20.dtd">
<BusinessRuleSet>
<ObjectID><localId>wt.businessRules.BusinessRuleSet:20001</localId>
</ObjectID>

<objectContainerPath>/wt.inf.container.OrgContainer=Demo Organization
/wt.pdmlink.PDMLinkProduct=Example1TestProduct</objectContainerPath>

<key>EXAMPLE1_RELEASE_RULE_SET</key>
<name>Example1_ReleaseRuleSet</name>
<enabled>true</enabled>
<description>Example1_ReleaseRuleSet</description>
<overridable>true</overridable>
<updateIfExists>true</updateIfExists>
</BusinessRuleSet>
5. Reload the site release target rule.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRule SYSTEM "standardX20.dtd">
<BusinessRule>
<ObjectID><localId>wt.businessRules.BusinessRule:20002</localId>
</ObjectID>

<key>RELEASE_TARGET</key>
<selector>RELEASE_TARGET</selector>
<name>com.ptc.windchill.enterprise.change2.change2ClientResource:
RELEASE_TARGET_RULE_NAME</name>

<description>com.ptc.windchill.enterprise.change2.
change2ClientResource:RELEASE_TARGET_RULE_DESC</description>

<enabled>true</enabled>
<updateIfExists>true</updateIfExists>
</BusinessRule>
6. Create the link for the target rule and required rule set.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRuleLink SYSTEM "standardX20.dtd">
<BusinessRuleLink>
<ObjectID><localId>wt.businessRules.BusinessRuleLink:20003</localId>
</ObjectID>

<ruleSet><ObjectReference><localId>wt.businessRules.BusinessRuleSet:
20001</localId></ObjectReference></ruleSet>

<rule><ObjectReference><localId>wt.businessRules.BusinessRule:20002
</localId></ObjectReference></rule>

<blockNumber>1</blockNumber>
<updateIfExists>true</updateIfExists>
</BusinessRuleLink>
7. Execute all required and nonrequired business rule sets. To display all required and nonrequired rule conflicts, update the Audit Change Notice workflow task conditional to use both rule sets EXAMPLE1_RELEASE_RULE_SET and EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET.
if (wt.change2.ChangeHelper2.isTrackingChange((wt.inf.container.
WTContained)primaryBusinessObject)) {

result = "Revisioning Enabled";
}else {
result = "Revisioning Disabled";
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] beans = new
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] {

// Configure to call non-required rule set
com.ptc.core.businessRules.engine.BusinessRuleSetBean.newBusinessRuleSetBean
("EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET", "wt.change2.ChangeRecord2"),

// Configure to call required rule set
com.ptc.core.businessRules.engine.BusinessRuleSetBean.newBusinessRuleSetBean
("EXAMPLE1_RELEASE_RULE_SET", "wt.change2.ChangeRecord2")
};
}
com.ptc.core.businessRules.validation.RuleValidationResultSet resultSet =
wt.businessRules.BusinessRulesHelper.engine.execute(primaryBusinessObject, beans);

if ( resultSet.hasResultsByStatus(com.ptc.core.businessRules.validation.
RuleValidationStatus.FAILURE)) {

businessRulesResultSetGlobal = wt.businessRules.BusinessRulesHelper.
serialize(resultSet);

preReleaseConflictsMsg = new wt.util.WTMessage("com.ptc.windchill.
enterprise.change2.change2ClientResource", com.ptc.windchill.enterprise.
change2.change2ClientResource.BUSINESS_RULES_PRERELEASE_VALIDATION_MSG,
null).getLocalizedMessage();

preReleaseConflictsMsg = preReleaseConflictsMsg + "\n" + resultSet.
getFailedRulesMessage(java.util.Locale.getDefault());
}
8. Execute the required business rule sets. In order to prevent the change notice workflow process for proceeding for the required business rules, update the conditional to use only the required rule set EXAMPLE1_RELEASE_RULE_SET for the Resolve Release Conflicts workflow task.
result = "NOT_READY";

com.ptc.core.businessRules.engine.BusinessRuleSetBean[] beans = new
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] {

// Configure to call required rule set only
com.ptc.core.businessRules.engine.BusinessRuleSetBean.
newBusinessRuleSetBean("EXAMPLE1_RELEASE_RULE_SET",
"wt.change2.ChangeRecord2")
};

com.ptc.core.businessRules.validation.RuleValidationResultSet
resultSet = wt.businessRules.BusinessRulesHelper.engine.execute
(primaryBusinessObject, beans);

if ( !resultSet.hasResultsByStatus(com.ptc.core.businessRules.
validation.RuleValidationStatus.FAILURE)) {

result = "PROCEED";
} else {
businessRulesResultSetGlobal = wt.businessRules.BusinessRulesHelper.
serialize(resultSet);

preReleaseConflictsMsg = new wt.util.WTMessage("com.ptc.windchill.
enterprise.change2.change2ClientResource", com.ptc.windchill.enterprise.
change2.change2ClientResource.BUSINESS_RULES_PRERELEASE_VALIDATION_MSG,
null).getLocalizedMessage();

preReleaseConflictsMsg = preReleaseConflictsMsg + "\n" + resultSet.
getFailedRulesMessage(java.util.Locale.getDefault());
}
The Resolve Release Conflicts workflow task continues to regenerate the task until all conflicts have been resolved.