Run Business Action Use Case - Simplified Approval Process
In this use case, the customer requires that a user who has made changes to information on a Multi-Reference screen should then be able to multi-select the changed items and approve the information that has been updated. The solution is to activate auto-save and configure the Run Business Action button so that clicking it will approve all changes made to values for the relevant attributes. For details, refer to the Auto-Save in the Web UI topic.
The configuration steps required to address this use case are described below:
-
Review requirement and assess solution. In this instance, a Multi-Reference component displays on a Node List configured on a product. The target objects being referenced are other products. The headers on the Multi-Reference screen display information from attributes on the referenced product. These attributes are grouped in an attribute group. With the appropriate business rule written and configured for the 'Approve' button, the user can make updates to any of the values under the grouped headers, multi-select the references upon which they have made updates, and click the 'Approve' button. The auto-save saves all updated values, and the business rule approves only those changes made to attributes on that target object. Validation is run on each selected reference and, for those that fail, a notification message has been configured to display following a click of the button.
-
Configure the business rule. Directly below is a screenshot of the business rule, as it displays in the workbench, that meets the above-described requirement. In the online help, beneath this screenshot is the text of the business rule that can be cut and pasted into the business rule editor in the workbench, and then edited as needed.
The binds required to enable this business rule are listed above the business rule itself. The bind that does the work of bringing the business rule into the Run Business Action component is the 'Web UI Context' bind. Regardless of the work the business rule is configured to do, the 'Web UI Context' bind must be included for the component to work.
Additional guidance about how this business rule has been written displays in green text in the screenshot below.
Copy// start by creating a HashSet containing all attribute IDs we want to evaluate for approval
var group = manager.getAttributeGroupHome().getAttributeGroupByID(attributeGroupID);
var attributeSet = group.getAllAttributes().iterator();
var attributeIdSet = new java.util.HashSet();
while (attributeSet.hasNext()){
var attribute = attributeSet.next();
attributeIdSet.add(attribute.getID());
}
// loop through each of the selected products and look for changes to approve
var selection = web.getSelection().iterator();
while (selection.hasNext()){
var node = selection.next();
var approvalSet = new java.util.HashSet();
var exceptionSet;
var exceptionMessage = "";
// loop through the set of unapproved part objects and build a set of those we care about
var unapprovedSet = node.getNonApprovedObjects().iterator();
while (unapprovedSet.hasNext()){
var partObject = unapprovedSet.next();
// if it is an attribute value, check if it is part of our group set
if (partObject instanceof com.stibo.core.domain.partobject.ValuePartObject){
if (attributeIdSet.contains(partObject.getAttributeID())){
approvalSet.add(partObject);
}
}
// also check for a name change
if (partObject instanceof com.stibo.core.domain.partobject.NamePartObject) approvalSet.add(partObject);
}
// if the approval set is not empty, attempt an approval
if (!approvalSet.isEmpty()){
try{
exceptionSet = node.approve(approvalSet);
}catch(e){
if (e.javaException instanceof com.stibo.core.domain.approve.ApproveBulkValidationException ||
e.javaException instanceof com.stibo.core.domain.synchronize.exception.SynchronizeException){
// provide some meaningful information to the user
exceptionMessage += " " + e.javaException.getMessage() + "<br/>";
}else{
// we cannot hide unhandled exceptions because the db transaction is already voided, so rethrow it
throw(e);
}
}
}
// check if the approve operation returned synchronize exceptions
if (exceptionSet && !exceptionSet.isEmpty()){
// one or more synchronize exceptions occurred - provide a meaningful user a message
var iter = exceptionSet.iterator();
while (iter.hasNext()){
var exception = iter.next();
exceptionMessage += " " + exception.getMessage() + "<br/>";
}
}
if (exceptionMessage){
exceptionMessages.put(node.getID(), exceptionMessage);
}
}
// create some user messaging
if (exceptionMessages.isEmpty()){
// no approval errors were caught, all is well
web.showAlert("ACKNOWLEDGMENT", "Selected items successfully approved");
}else{
// some errors were caught, format error message list
var headline = "Approval Errors";
var message = "";
var errorNodes = exceptionMessages.keySet().iterator();
while (errorNodes.hasNext()){
var errNode = errorNodes.next();
message += "Errors for item: " + errNode + "<br/>";
message += exceptionMessages.get(errNode) + "<br/>";
}
web.showAlert("ERROR", headline, message);
}
// refresh the page to make sure the user gets the current values
web.navigate; -
Add the button. With the business rule created, users can now configure this component in the Web UI.
Because the button should only be accessible on the Multi Reference Editor screen for this use case, the component will be added as a Toolbar Action button on that screen. In this instance, the Multi-Reference Editor screen is configured as a Node List Tab Page on a Node Details screen.
The Run Business Action component should be added as a toolbar action button in the 'Actions' field.
-
Configure the button. To configure the Run Business Action component as a toolbar action for this use case, review the bullets below:
-
On the 'Business Action' parameter, click the ellipsis button (
) to select the relevant business rule from a Node Picker. In this case, the business rule is titled 'ApproveReferenceData'.
-
In the field for the 'Max Number of Nodes,' set a maximum number of nodes. This number determines the maximum number of nodes a Run Business Action can be executed on. If the number is set too high, performance issues can result from a large selection.
-
On the 'Label' parameter, add text that describes in two or three words what action clicking the button will execute. In this case, because the operative business rule approves changes made to values in the attribute group, the button label text is 'Approve'.
-
'Enable On Workflow Only' should not be checked as this component's configuration does not touch on workflows.
-
-
Result. Now when a user has made changes to one or more references, the 'Approve' button will be enabled.
When the 'Approve' button is clicked with one or more references multi-selected, the button initiates a validation process. If no issues are detected with the approve action, a custom notification will display to that effect:
If the validation process detects issues with the approve action, a custom notification displays describing the items that could not be approved and why.