JavaScript Function

The default Business Function operation is the 'JavaScript Function' and displays as 'JavaScriptBusinessFunctionWithBinds' on the Function tab. This operation allows users to define their own functions using JavaScript while binding various STEP data for use.

To add the JavaScript to this operation, click the Edit Business Function link.

For more information on editing a business function, see the Editing a Business Rule topic in the Business Rules documentation here.

Configuration

In this section, you will find an example of how to configure a Business Function that displays the text of a referenced object's attribute value description.

  1. JavaScript Binds - This section allows users to bind various STEP objects to JavaScript.

Note: The dynamic binds available for business functions are 'STEP Manager' and 'Logger.'

For more information on STEP JavaScript Binds, see the JavaScript Binds topic (here) as well as the Adding a Bind topic (here) in the JavaScript section.

  1. Via the Messages section, it is possible to define localized error messages that can be returned when an error condition is encountered with this business function. For more information on translatable JavaScript messaging, see the Localized Messages for JavaScript Business Rules topic in the JavaScript section here.
  1. The Input Parameter section is used for defining the parameters that can be passed to the function to produce an output. A number of STEP and Java types are available.

Using the provided example, when a user calls this Business Function, they must provide an attribute, references, or a product, which are passed as objects.

  1. Via the Return Type section, it is possible to define what type of data the business function returns. The only data type that is acceptable as returns from business functions are Java Strings.
  1. The JavaScript section is where the function logic must be entered. In this example, the values of attributes on referenced objects is returned. The full code used for this functionality is:
var referencesArray = product.getReferences(accReferenceType).toArray();
var desc = "";
for (var i = 0; i < referencesArray.length; i++){
	var accessoryDesc = referencesArray[i].getTarget().getValue(accDescAttribute.getID()).getSimpleValue();
	if (accessoryDesc != null){
		if (i != 0){
			desc += ", ";
		}
		desc += accessoryDesc;
	}
}
 
return "Compliant accessories: " + (desc.length == 0 ? "None" : desc);

See the Calling a Business Function from a JavaScript Business Rule topic for information on executing and testing business functions here.

2018, Stibo Systems