Procedure — Creating a Custom Business Rule Result Action
The following steps provide an example of how to create a custom action which executes a set of business rules for Change Notice resulting objects and display the results. The action to evaluate the business rule results is made available in the change notice action menu.
Extend Business Rules Results Table
Extend the AbstractBusinessRulesResultsTable class and override the getRuleValidationResultSet API to execute the desired rule sets. See Customizing Business Rules for more details on executing a set of business rules. The following is an example of a custom business rules result table builder which executes the business rules for the resulting object on a change notice:
package com.custom.businessRules.mvc.builders;

@ComponentBuilder("CustomBusinessRulesResultsTable")
public class CustomBusinessRulesResultsTable extends
AbstractBusinessRulesResultsTable {

private static final Logger logger =
LogR.getLogger(CustomBusinessRulesResultsTable.
class.getName());

/**
* {@inheritDoc}
*/
@Override
public RuleValidationResultSet
getRuleValidationResultSet(NmCommandBean commandBean)
throws WTException {
RuleValidationResultSet resultSet = new RuleValidationResultSet();
logger.debug("Get context object.");
NmOid contextOid = commandBean.getActionOid();
if(contextOid.isA(WTChangeOrder2.class)) {
logger.debug("Context object is a change notice.");

BusinessRuleSetBean[] ruleSetBeans = new BusinessRuleSetBean[] {
BusinessRuleSetBean.newBusinessRuleSetBean
("CHANGEABLE_PRE_RELEASE",
ChangeRecord2.class.getName())
};
logger.debug("Executing the CHANGEABLE_PRE_RELEASE rule
set for the change notice resulting objects.");
resultSet = BusinessRulesHelper.
engine.execute(contextOid.getRefObject(),
ruleSetBeans);
}

return resultSet;
}
}
Register the Custom Table Builder
The builder is registered by adding the following line in /<windchill>/codebase/config/mvc/custom.xml.
<mvc:builder-scan base-package="com.custom.businessRules.mvc.builders"/>
Define Actions
Define Business Rules Results Action
Define a new action in <Windchill>/codebase/config/actions/custom-actions.xml to launch a popup window that displays the business rules results.
<objecttype name="customBusinessRules"
resourceBundle="com.custom.customClientActionsRB">
<action name="customBusinessRulesResultWizard">
<command windowType="popup"/>
</action>
</objecttype>
The new action requires new action properties defined in a custom resource file. See Windchill Client Architecture Action Framework Overview for more details on defining new actions. The following is an example of properties configured for the custom action:
@RBEntry("View Rule Conflicts")
@RBComment("Title of the wizard that displays business rules results")
public static final String PRIVATE_CONSTANT_0 =
"customBusinessRules.customBusinessRulesResultWizard.description";

@RBEntry("View Rule Conflicts")
@RBComment("Title of the wizard that displays business rules results")
public static final String PRIVATE_CONSTANT_1 =
"customBusinessRules.customBusinessRulesResultWizard.title";

@RBEntry("View Rule Conflicts")
@RBComment("Title of the wizard that displays business rules results")
public static final String PRIVATE_CONSTANT_2 =
"customBusinessRules.customBusinessRulesResultWizard.tooltip";

@RBEntry("width=940,height=600")
@RBPseudo(false)
@RBComment("DO NOT TRANSLATE")
public static final String VIEW_CONFLICTS_MOREURLINFO =
"customBusinessRules.customBusinessRulesResultWizard.moreurlinfo";
Define Business Rules Results Table Step Action
Using the ComponentId defined in the custom table builder in the “Define Business Rules Results Action” section above, define a new action to display the business results table in /<windchill>/codebase/config/actions/custom-actions.xml.
<objecttype name="customBusinessRules" resourceBundle=
"com.custom.customClientActionsRB">
<action name="customBusinessRulesResultStep">
<component name="CustomBusinessRulesResultsTable"/>
</action>
</objecttype>
Define Business Rules Results Action JSP
In order to display the table when launching the custom business rule action a single step wizard needs to be defined using a jsp file. The name of the jsp should match the name of the action and should be in a package with the same name of the action object type under directory <Windchill>/codebase/netmarkets/jsp. For the action defined in the “Define Business Rules Results Action” section above, the package and name is:
<Windchill>/codebase/netmarkets/jsp/customBusinessRules/customBusinessRulesResultWizard.jsp
The following jsp sample describes a single step wizard which includes the action defined in the “Define Business Rules Results Table Step Action” section. For more details about describing wizards, see Windchill Client Architecture Wizard.
<%@ taglib prefix="jca"
uri="http://www.ptc.com/windchill/taglib/components"%>
<%@ include file="/netmarkets/jsp/components/beginWizard.jspf"%>
<!-- Need to set isWizard and popupWindow to false in
order to display links on number and the info
page action icon. -->
<% request.setAttribute("isWizard","false"); %>
<script src="netmarkets/javascript/businessRules/
businessRulesResultsPlugin.js"></script>
<script type="text/javascript">
<!-- Converts all links to open in new window -->
PTC.onReady(function() {
JCAappendFormHiddenInput(getMainForm(), "popupWindow", "false");
});
</script>

<jca:wizard buttonList="OkCancelWizardButtons">
<jca:wizardStep action="customBusinessRulesResultStep"
type="customBusinessRules"/>
</jca:wizard>

<%@include file="/netmarkets/jsp/util/end.jspf"%>
Add the Business Rules Results Action to a Menu
The new custom action must be added to an object action model. A /<windchill>/codebase/config/actions/custom-actionModels.xml is available for adding or overriding actions models. The following sample shows how to add a custom action to existing action model for a change notice:
<actionmodels resourceBundle="com.ptc.windchill.enterprise.
change2.changeManagementActionsRB">
<model name="more change notice row actions"
menufor="wt.change2.WTChangeOrder2">
<description>Change notice row actions</description>
<action name="customBusinessRulesResultWizard"
type="customBusinessRules"/>
.
.
<!-- Existing Actions -->
.
.
</model>
</actionmodels>
Isto foi útil?