Current Object Bind

The Current Object bind gives access to the STEP object that the business rule is being evaluated (via condition) or executed (via action) against. The bind can be found within the 'Binds to' dropdown, as shown below.

Note: If the Current Object is bound into JavaScript, the business rule cannot be used in the Web UI.

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.

Examples

The following JavaScript examples use the related bind(s).

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.

This sample code above expects a bind to currentObject, gets the value of the 'Description' attribute on the current object, and stores it in the variable 'descr'.

Condition Examples

The following condition samples expect a bind to Current Object with the variable 'currentObject' and a bind to STEP Manager with the variable 'stepManager'.

Simple Value Test

This condition checks the attribute 'SellPackWeight', and returns a message if the value is five or greater.

Using the same binds, the condition could alternatively be written as:

Copy
return currentObject.getValue("SellPackWeight").getValue() < 5 ? true : "Shipping Weight should be less than 5";

With an additional bind of Attribute Value to the variable sellPackWeight (for attribute 'Sell Pack Weight'), the same output could be achieved as:

Condition for Object Type Test

This JavaScript returns true or false, dependent on whether the current object is of the Object Type = SalesItem:

Copy
return currentObject.getObjectType().getID() == "SalesItem";

Condition to Check Data on Referenced Objects

This JavaScript iterates over references of the type 'Part of Kit' and evaluates to true if none of the referenced objects has a shipping weight greater than or equal to five:

Copy
var refType =
stepManager.getReferenceTypeHome().getReferenceTypeByID("Accessory");
var refsList = currentObject.getReferences(refType);
var result = true;
for(var i = 0; i < refsList.size(); i++) {
if(refsList.get(i).getTarget().getValue("SellPackWeight").getValue() > 5) {
result = "Accessory with ID '" + refsList.get(i).getTarget().getID() + "' is too heavy";
    break;
  }
}
return result;

Action Examples

The following action samples expect a bind to Current Object with the variable 'node' and a bind to STEP Manager with the variable 'step'.

Action to Set Value

The following sample sets the value for the 'Live' attribute as Yes.

Copy
currentObject.getValue("Live").setSimpleValue("Yes");

The following sample adds a reference to the object, checking first that the reference does not already exist (local or inherited).

Copy
var refType = stepManager.getReferenceTypeHome().getReferenceTypeByID("Accessory");
var targetObj = stepManager.getProductHome().getProductByID("I-SalesItem-1122");
var refsList = currentObject.getReferences(refType);
var refExists = false;
for(var i = 0; i < refsList.size(); i++) {
   if(refsList.get(i).getTarget().getID().equals(targetObj.getID())) {
      refExists = true;
      break;
   }
}
if (!refExists) {
currentObject.createReference(targetObj, refType);
}

Note: When creating a business rule that uses the CurrentObject bind for use in the Web UI, specifically for use with the Run Business Action button, be aware that errors can result from application of a business rule on Task Lists. This is because when viewing product data via a Task List, no 'current node' is specified for which the 'CurrentObject' bind can derive that information. Instead, business action writers should access the selected nodes from a Web UI context object. The Web UI Context bind is often suitable for this scenario.