Approve Context Bind

Business rules tested via conditions or executed via actions during approval have access to the Approve Context bind. The Approve Context bind is applicable before approval or on approval. Its use varies between actions and conditions. Refer to the Business Conditions and Business Actions sections below for details and the available methods.

The bind can be found within the 'Binds to' dropdown, as shown below.

Configuration

To use any bind:

  1. Create a business rule as defined in the Creating a Business Rule, Function, or Library topic.

  2. Edit the business rule as defined in the Editing a Business Rule or Function topic.

  3. In the Edit Operation dialog, add the bind to a business rule, as defined in the Adding a Bind topic in the Resource Materials online help documentation.

  4. In the Edit Operation dialog, optionally add Messages, as defined in the Localized Messages for JavaScript Business Rules topic.

  5. In the Edit Operation dialog, add JavaScript to call the bind.

JavaScript Methods

The interface has the following methods that can compare data in Main or Approved workspaces, and can also access the set of part objects to be synchronized:

getApprovedManager()
getApprovedNodeBeforeApproval()
getApprovedNode()
getMainManager()
getMainNode()
getPartObjects()

Note: Business rules used in OIEPs or Event Processors as event filters or event generators run after approval (when required). Use the 'getApprovedNodeBeforeApproval()' method to inspect the node as it looked prior to the approval, or use the 'getApprovedNode()' method to return the node after approval.

Business Condition

When used in a Business Condition On Approval, the bound class is 'ApprovePlugin.ApproveContext'.

When called Before Approval, the following code checks if the current node is already in the approved workspace. It evaluates to false if the node is not in the approved workspace.

Example

The following is an example JavaScript that uses this bind.

Important: Example scripts should not be used as-is without thorough testing, including updating the script to match object and link types that exist on your system. JavaScript variable names are case-sensitive.

Copy
if(approveContext.getApprovedManager().getProductHome().getProductByID(node.getID())) {
return true;}
else {return "Node not in Approved Workspace";}

Be aware that the condition After Approval check is carried out in the Approved workspace after data has been synchronized. In this case, the getApprovedNode() method would return the object post synchronization.

For standard approval condition checks, you will likely not have to use the Approve Context at all. Thus, a simple value check, like the Current Object bound as 'node' below, will automatically resolve to the Main node Before Approval and the Approved node (post synchronization) After Approval.

Copy
var ean = node.getValue("EAN").getSimpleValue();
return ean != null && ean.length() == 13 ? true : "EAN must have 13 digits";

Business Action

When used in a Business Action, the bound class is 'ApproveTrigger.ApproveTriggerContext' and can be used when running On Approve.

Example

The following is an example JavaScript that uses this bind.

Important: Example scripts should not be used as-is without thorough testing, including updating the script to match object and link types that exist on your system. JavaScript variable names are case-sensitive.

In this example, in actions executed during approval, the Approve Context binding gives access to a super type-specific sub-interface for products: ApproveProductTrigger.ApproveProductTriggerContext. Using these sub-interfaces you can add part objects changed by an action during approval to the set of part objects to be approved as shown below:

Copy
var valObj = node.getValue("ReadyForWebsite");
valObj.setSimpleValue("Yes");
approveContext.approveValue(valObj);

Note: Actions executed On Approval can have changes synchronized automatically in the Business Rule Editor 'On Approve' action parameter by checking the 'Approve changes to current object' checkbox. For more information, refer to the On Approve Parameter section of the Editing a Business Rule or Function documentation here.