Share

Scripting Basics

Learn about script types and triggers, access to item fields, permissions and security considerations, and more.

Script Types and Triggers

Script TypeDescriptionTriggersExamples
ConditionChecks for a precondition before showing a workflow transition to the user (return "True" or "False").
  • Workflow transition
  • Show a workflow transition to the user only if all the required approvals have been made.
  • Hide a workflow transition unless the login user is the item Owner.
ValidationValidates certain requirements before allowing transitioning to the next state in a workflow. If validation fails, provides feedback to the user from an array of messages explaining why.
  • Workflow transition
  • Allow only items with XYZ Co. as the manufacturer to transition to the next step in a workflow. If validation fails, return the message: "The transition can be completed only by workspace items with XYZ Co. as the manufacturer."
Action ConditionPerforms an action on a workspace; sends an email message.
  • Workflow transition
  • Workflow escalation
  • Workspace behavior
  • Spawn a new item in a workspace after successful execution of a workflow transition.
  • Create a set of milestones for an item after the item is created.
  • Perform a transition from an escalated workflow state.
LibraryContains functions that can be used in other scripts.

Import into another script

  • Determine if the passed value is an element of the passed array.
  • Create a set of milestones.

The item Object and Access to Item Fields

The scripting engine automatically loads the associated workspace item into the item object. Follow these guidelines to access item field values through the object:

  • Item Detail Fields. Implemented as properties on the item object. The name of a property must be set to the ID assigned to the field when configured. For example, a Detailed Notes field with the ID DETAILED.NOTES is represented as item.DETAILED.NOTES.

    Important:

    Configured workspace item fields are referenced by Field ID. Field IDs are always in upper case.

  • Multi Select Fields. Implemented as a standard JavaScript object array. Use of the indexOf function is supported to determine if an array contains a specific item.

    Warning:

    Because of likely unstable behavior, we strongly discourage you from using the typeOf JavaScript keyword.

  • Picklist Values. Represented as the actual value entered when the list is created.

Important:

In a previous release, the scripting engine required the use of the loadItem(dmsID) function to load the item object. For backwards compatibility, the engine continues to support the function. However, the function is deprecated, and we recommend that you do not use it going forward.

Access to linked item data

Because a property on the item object can represent another workspace as well as an item field, scripts can access data in linked items, as shown in this example:

if item.MANUFACTURING_PLAN.STATUS == 'Complete'
  returnValue(true);
else
  returnValue(false); 

Here, the MANUFACTURING_PLAN property is a field of the workspace item that is actually a link to an item in another workspace (for example, "Manufacturing Plan"), and the STATUS property is a lookup field of the linked item.

Return Value Requirement

All Condition and Validation scripts must return a value and can use the returnValue() function to do so. The value returned by a script is evaluated to determine whether the precondition is met (true/false) or the validation is successful (pass/fail).

Note If returnValue() is called multiple times in a script, the value of the last call is the "winner."

Example:

if (item.STATUS == 'OPEN' || item.STATUS == "PENDING')
  returnValue(true);
else 
  returnValue(false);
Important:

For backwards compatibility, the scripting engine continues to support returning a value with the "return value" as the last statement in the script.

Permissions and Security Considerations

Permissions

Scripting is part of the Setup Administration permission. A typical setup to grant the permission to a user is as follows:

  1. Add the Setup Administration permission to an Administrator role.
  2. Associate the Administration role with an Administrator group.
  3. Add the user to the Administrator group.

Security considerations

Scripting is an advanced feature of Fusion Manage. We recommend that you limit the feature to Administrators with some background in programming.

Important:

The scripting engine does NOT honor the Fusion Manage permissions assigned to the current user. To control scripting permissions, use Security functions.

Was this information helpful?