JavaScript Function Operation

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

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

For more information on editing a business function, refer to the Editing a Business Rule or Function topic in the Business Rules documentation.

Refer to the Custom Reference Target Search topic in the Web User Interfaces documentation for more information on creating reference editors that target objects the user is allowed to select based on the object type validity configured on the reference type.

Configuration

The example in this section configures a JavaScript Function to display the text of a referenced object's attribute value description.

  1. Binds - bind STEP objects to the JavaScript, including the 'STEP Manager' and 'Logger' dynamic binds available for business functions. For more information on JavaScript Binds, refer to the JavaScript Binds topic as well as the Adding a Bind topic in the Resource Materials online help documentation.

  2. Messages - 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, refer to the Localized Messages for JavaScript Business Rules topic.

  3. Input Parameter - define parameters that can be passed to the function to produce an output. A number of STEP and Java types are available.

    For a custom reference target search, use one of these:

    • String: Populated with the search string the user has entered. Most cases require a String input.

    • Node: Populated with any node selected. When creating a reference, this will be the source node of the reference. Most cases require a Node input.

    • Data Container Object: If the user is within a data container editor, the source of the reference will be a data container instance, and this source will be available to the business function as a Data Container Object.

    Note: Use caution when changing an input parameter type for an active JavaScript Function business rule. Business rules that call the modified function may also need updating.

    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.

  4. Return Type - define the type of data returned by the business function.

    Note: Use caution when changing a return type for an active JavaScript Function business rule. Business rules that call the modified function may also need updating.
    Also, it is important to note that JavaScript Business Functions configured to return either a 'Double' or an 'Integer' or lists of these types should be specified in the return command rather than relying on the JavaScript to Java type conversion. For example, to return an integer value of 3 use:

    return new java.lang.Integer(3); 

    instead of
    return 3;

    In the latter case, return values that are in fact integers may not be recognized as such and will produce errors.

    For a custom reference target search, the business function must return a 'Query Specification.' Otherwise, the business function cannot be selected in the Web UI for Target Search Function in the Search Table Tab Properties (for the References component Node Picker Dialog) as described later in this topic.

  5. JavaScript - add function logic. 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);
    

    For a custom reference target search, the business function must return a 'Query Specification.' Otherwise, the business function cannot be selected in the Web UI for Target Search Function in the Search Table Tab Properties (for the References component Node Picker Dialog) as described in the Custom Reference Target Search Configuration topic of the Web User Interfaces documentation.

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

Functions can also be edited externally via the Edit Externally button found on the Business Function tab.

For more information about editing functions externally, refer to the Editing a JavaScript Business Rule Externally topic.