2Debug Your Groovy Scripts

Use the Groovy script debugger in Application Composer to debug the object functions and validations that you defined for an object. While debugging, you can also examine object and attribute values.

Access the Groovy Script Debugger

Access the Groovy script debugger from either the Custom Objects or Standard Objects page in Application Composer.

To access the debugger:

  1. In Application Composer, in the Objects tree, click either the Custom Objects or Standard Objects link.
  2. On the resulting Objects page for either custom or standard objects, select the object that you want to debug and then click the debugger icon in the table's toolbar.

    The debugger icon is a ladybug.

  3. On the debugger UI, examine the object functions and validations defined in Groovy for that object.

Use the Groovy Script Debugger

The Groovy script debugger contains multiple regions, described in the following table, which you can use to debug your scripts for an object:

Groovy Script Debugger Regions

Debugger Region

Description

Main toolbar

From the toolbar, you can select the object to examine and start the debugging process.

Left pane region

This region displays the object functions and validations defined for the selected object.

Main script region

This region displays the selected Groovy script.

Stack region

This region displays the call stack. For example, assume there are two functions, Function1 and Function2. Function1 calls Function2. When debugging within Function2, the Stack region displays which statement from Function2 is currently being executed, as well as information about the parent Function1 from where Function2 was called.

Variables region

This region displays variables and associated values.

Breakpoints tab

This tab displays which statement (line number) has a breakpoint. A breakpoint is a location in a Groovy script where you want the script to pause during debugging. The debugger stops at that statement.

Log tab

This tab displays all logs. If the script has any println() statements, then those values are captured on this tab.

To use the debugger:

  1. In Application Composer, in the Objects tree, click either the Custom Objects or Standard Objects link.
  2. On the resulting Objects page for either custom or standard objects, select the object that you want to debug and then click the debugger icon in the table's toolbar.
  3. On the debugger UI, the left pane displays the object functions and validations defined in Groovy for that object. Select the script that you want to review.

    The script is displayed in the main script region.

  4. To start debugging, click one of these icons in the toolbar:
    • Step Over

      Review one statement in the selected script at a time.

    • Step Into

      If a statement in execution is a call to some function, and you want to debug inside that function, then click Step Into.

    • Step Out

      If you're debugging inside a child function and you want to move the control back to the parent function, then click Step Out.

    • Run

      Move to the next breakpoint in the script. If no further breakpoints exist, then the debugger completes its evaluation of the selected script and then closes the debugger session.

Enable or Disable the Groovy Script Debugger

The Groovy script debugger is enabled by default. However, to hide the debugger, or later show it again, then set the ADF: Enable Script Debugger profile option.

To set the ADF: Enable Script Debugger profile option:

  1. In the Setup and Maintenance work area, go to: Sales offering > SalesFoundation functional area > Manage Administer Profile Values task.

  2. In the Profile Display Name field, enter ADF: Enable Script Debugger and click Search.
  3. In the Profile Values region, at the Site level, enter either TRUE or FALSE.
    • TRUE displays the debugger.
    • FALSE hides the debugger.

Notifications Sample Groovy Scripts

Use Groovy scripts to define the start of notifications. Here's sample code to generate notifications to the recipients specified in the Notification Preferences page for sales objects. You can change the scripts to fit your requirements.

Scripts for Standard Objects

Here are sample scripts for standard sales objects:

Sample Groovy Scripts for Notifications

Object

Scenario

Create and Assign Scripts

Accounts

Push notification received

Account Create

// Send notification to Owner when Account is created // Use trigger type BEFORE INSERT TO DATABASE def map = new HashMap(); // Specify one or more channels map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText def messageText = "Account created with name: " + OrganizationName; map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", OwnerPartyId); adf.util.sendNotification(adf, map)

Accounts

Drill down to details page

Account Assign

// Send notification to Owner when Account is assigned to them // Use trigger type BEFORE UPDATE TO DATABASE if (isAttributeChanged('OwnerPartyId')) { try { def map = new HashMap(); def messageText = "This Account has been assigned to you" def recipientPartyId = OwnerPartyId // Specify one or more channels map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", recipientPartyId); if (recipientPartyId) { adf.util.sendNotification(adf, map) } else { println("No Owner associated with this Account") } } catch (e) { throw new oracle.jbo.ValidationException('Failure: ' + e.getMessage()) } }

Contacts

Push notification received

Contact Create

// Send notification to Owner when Contact is created // Use trigger type BEFORE INSERT TO DATABASE def map = new HashMap(); // Specify one or more channels map.put("Channels",[ "ORA_SVC_BELL"]); // Specify default MessageText def messageText = "Contact created with name: " + PersonName; map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", OwnerPartyId); adf.util.sendNotification(adf, map)

Contacts

Drill down to details page

Contact Assign

// Send notification to Owner when Contact is assigned to them // Use trigger type BEFORE UPDATE TO DATABASE if (isAttributeChanged('OwnerPartyId')) { try { def map = new HashMap(); def messageText = "This Contact has been assigned to you" def recipientPartyId = OwnerPartyId // Specify one or more channels map.put("Channels",[ "ORA_SVC_BELL"]); // Specify default MessageText map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", recipientPartyId); if (recipientPartyId) { adf.util.sendNotification(adf, map) } else { println("No Owner associated with this Contact") } } catch (e) { throw new oracle.jbo.ValidationException('Failure: ' + e.getMessage()) } }

Leads

Push notification received

Lead Create

// Send notification to Owner when Lead is created // Use trigger type BEFORE INSERT TO DATABASE def map = new HashMap(); //give lead object API name def objectCode = 'MklLeadVO' map.put("ObjectCode", objectCode) // Specify one or more channels map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText def messageText = "Lead created with name: " + Name; map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", OwnerId); adf.util.sendNotification(adf, map);

Leads

Drill down to details page

Lead Assign

Lead Assign // Send notification to Owner when Lead is assigned to them // Use trigger type BEFORE UPDATE TO DATABASE if (isAttributeChanged('OwnerId')) { try { def map = new HashMap(); def messageText = "This Lead has been assigned to you" def recipientPartyId = OwnerId // Specify one or more channels map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", recipientPartyId); if (recipientPartyId) { adf.util.sendNotification(adf, map) } else { println("No Owner associated with this Lead") } } catch (e) { throw new oracle.jbo.ValidationException('Failure: ' + e.getMessage()) } }

Opportunities

Push notification received

Opportunity Create

// Send notification to Owner when Opportunity is created // Use trigger type BEFORE INSERT TO DATABASE def map = new HashMap(); // Specify one or more channels map.put("Channels",["ORA_SVC_BELL"]); // Specify default MessageText def messageText = "Opportunity created with name: " + Name; map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", OwnerResourcePartyId); adf.util.sendNotification(adf, map)

Opportunities

Drill down to details page

Opportunity Assign

// Send notification to Owner when Opportunity is assigned to them // Use trigger type BEFORE UPDATE TO DATABASE if (isAttributeChanged('OwnerResourcePartyId')) { try { def map = new HashMap(); def messageText = "This Opportunity has been assigned to you" def recipientPartyId = OwnerResourcePartyId // Specify one or more channels map.put("Channels",[ "ORA_SVC_BELL"]); // Specify default MessageText map.put("MessageText", messageText); // The following can be used to pass a Long PartyId map.put("RecipientPartyId", recipientPartyId); if (recipientPartyId) { adf.util.sendNotification(adf, map) } else { println("No Owner associated with this Opportunity") } } catch (e) { throw new oracle.jbo.ValidationException('Failure: ' + e.getMessage()) } }
Tip: In these scripts, you're only enabling the bell icon in the global header. To enable notifications for other channels (for example, browser and mobile), use this syntax: // Specify one or more channels map.put("Channels",["ORA_SVC_BELL", "ORA_SVC_OMNI","ORA_SVC_MOBILE"]););
  • ORA_SVC_BELL: Notifications icon in the global header
  • ORA_SVC_OMNI: Notifications icon in the browser
  • ORA_SVC_MOBILE: Mobile notifications

Groovy Script for Custom Objects

You can use a Groovy script to send notifications for custom objects.

Prerequisites:

  • Use the global function, adf.util.sendNotification (adf, map).
  • The ObjectCode needs to be explicitly passed as part of the request parameter hash map in the Groovy trigger.
  • Your custom object needs to be published.

Sample Groovy Script for Custom Object Notifications

Object

Scenario

Create and Assign Scripts

Custom object

Send bell notification to the user based on the user's party ID

try { Long recipientPartyId = 100010037456865 def messageText = 'A custom object notification (default message).' def objectCode='CustomObject_SR_c' def map = new HashMap(); map.put("Channels", ["ORA_SVC_BELL"]); map.put("MessageText", messageText); map.put("RecipientPartyId", recipientPartyId); map.put("ObjectCode", objectCode); adf.util.sendNotification(adf,map) println("Triggered a notification"); } catch (e) { // Log the failure in groovy logging. Logs can be viewed in 'Runtime Messages'. println("Failure to trigger notification from Groovy Script " + e.getMessage()); }

To find the Object Code for your custom object, navigate to the overview page for the object. The API name is listed in the Object Information region of that page.