How Object Workflows and Groovy Scripts Work Together

You can use object workflows to trigger Groovy scripts. When you configure object workflows, you also specify the actions that the workflow must perform when triggered.

One of the actions you configure is the Groovy Script action. Use an object workflow with a Groovy Script action to perform long-running or performance-intensive Groovy scripts.

Before you begin, you might want to read Object Workflows: Explained and its related topics to familiarize yourself with what object workflows are, how you set trigger conditions, and the event actions that object workflows support.

Overview

A Groovy script action in an object workflow lets you call an external Groovy object function that has been previously defined. For example, you might trigger a Groovy action to perform cross-object updates, perform post-processing of large object hierarchies, or asynchronously call Web services.

As a simple example, let's assume that when you close an opportunity, you also want to close all the associated activities for that opportunity.

Using a trigger could cause a delay if the opportunity includes many associated activities, so instead you define an object workflow to trigger when the opportunity's status is updated to Lost. The object workflow calls a Groovy object function that queries the activities related the opportunity and sets their status to "Canceled."

Note: Typically, real-world processing logic used in Groovy script actions is much more complex than the simple example described here.

You configure a Groovy Script action in object workflows by defining an object function, then creating an object workflow that, when launched at run time, executes the object function. For examples of how you configure various event actions in object workflows, see Configuring Object Workflows and Configuring Object Workflows to Trigger Approval Requests for Creating Sales Leads.

Configuring a Groovy Script Action in Object Workflows

To configure a Groovy Script action:

  1. Navigate to Application Composer.

  2. On the Overview page, click Object Workflows.

  3. Select Create from the Actions menu.

    The Create Object Workflow page opens.

  4. Specify a name for your workflow.

  5. Specify the trigger condition in the Event Point and Condition region.

  6. Under the Actions region, click Create for Groovy Script.

    Create Object Workflow page showing Groovy Script option under Actions

    The Create Action: Groovy Script page opens. You use this page to specify the Groovy object function you want to call.

    This figure shows the Create Action: Groovy Script page.

    Create Action: Groovy Script page
  7. Provide a meaningful name for your Groovy Script action.

  8. Specify an Execution Schedule.

  9. Select a Method Name from the drop-down list. This list displays all Groovy object functions that are visible to the action. You can also click the plus sign next to the Method Name field to display the Create Object Function page and define a new function. See Defining an Object Function for Use in Object Workflows.

    The script appears in read-only form in the Script field.

    Note: If your Groovy Script action triggers a long-running process that's implemented via ESS/PLSQL, any Groovy triggers already created on the target object won't get called. This is because ESS/PLSQL operates directly at the database level, bypassing ADF and the model layer.
  10. Click Save.

Defining an Object Function for Use in Object Workflows

If you haven't previously defined an object function to select from the Method list on the Create Action - Groovy Script page when creating your object workflow, you can define one directly from that page. To define an object function for use with the Groovy Script action:

  1. On the Create Action - Groovy Script page, click the plus sign next to the Method Name field.

    The Create Object Function page displays.

  2. Enter a name for the function.

  3. Select void in the Returns field.

    Create Object Function page showing required elements for a Groovy function usable with Object Workflows
  4. Select Callable by External Systems in the Visibility field.

  5. Do not specify any input parameters.

  6. Enter the script in the Edit Script field.

  7. Click the Validate button to validate the script, and fix any errors.

  8. Click Save and Close.

Your object function is now ready to be called by a Groovy Script action in your object workflow. You can select it from the Method list when configuring an object workflow's Groovy Script action.