Contents
1 Introduction
2 Groovy Basics
- Commenting Your Scripts
- Defining Variables
- Referencing the Value of a Field in the Current Object
- Working with Numbers, Dates, and Strings
- Using Substitution Expressions in Strings
- Using Conditional Expressions
- Using the Switch Statement
- Returning a Boolean Result
- Assigning a Value to a Field in the Current Object
- Writing Null-Aware Expressions
- Understanding the Difference Between Null and Empty String
- Understanding Secondary Fields Related to a Lookup
- Using Groovy's Safe Navigation Operator
- Assigning a Value to a Field in a Related Object
- Printing and Viewing Diagnostic Messages
- Working with Lists
- Working with Maps
- Working with Ranges
3 Examples of Each Context Where You Can Use Groovy
- Providing an Expression to Calculate a Custom Formula Field's Value
- Providing an Expression to Calculate a Custom Field's Default Value
- Providing an Expression to Make a Custom Field Conditionally Updateable
- Providing an Expression to Make a Custom Field Conditionally Required
- Defining a Field-Level Validation Rule
- Defining an Object-Level Validation Rule
- Defining Utility Code in a Global Function
- Defining Reusable Behavior with an Object Function
- Controlling the Visibility of an Object Function
- Defining an Object-Level Trigger to Complement Default Processing
- Defining a Field-Level Trigger to React to Value Changes
4 Groovy Tips and Techniques
- Simplifying Code Authoring with the Expression Palette
- The Expression Editor Toolbar
- Showing and Hiding the Expression Palette
- Inserting an Expression for Fields of Related Objects
- Inserting Field Name of Object in Related Collection
- Inserting a Related Object Accessor or Related Collection Accessor Field Name
- Validating the Syntax and Correctness of Your Script
- Using the Related Object Accessor Field to Work with a Parent Object
- Using the Related Object Accessor Field to Work with a Referenced Object
- Using the Related Collection Accessor Field to Work with Child Rows
- Accessing Current Date and Time from the Application Server
- Accessing Current Date and Time from the Database
- Understanding ADF's Additional Built-in Groovy Functions
- Testing Whether a Field's Value Is Changed
- Avoiding Validation Threshold Errors By Conditionally Assigning Values
- Prefer "Before" Save-time Triggers to "After" Ones for Best Performance
- Detecting Row State in After Changes Posted to Database Trigger
- Avoiding Posting Threshold Errors By Conditionally Assigning Values
- Functional Restrictions in Trigger Scripts
- Passing the Current Object to a Global Function
- Referencing Original Values of Changed Fields
- Raising a Warning From a Validation Rule Instead of an Error
- Throwing a Custom Validation Exception
- Returning Locale-Sensitive Custom Strings
- Raising a Trigger's Optional Declaratively-Configured Error Message
- Accessing the View Object for Programmatic Access to Business Objects
- Defining the Sort Order for Query Results
- Finding an Object by Id
- Finding Objects Using a View Criteria
- Using a Simple View Criteria
- Syntax of View Criteria Filter Expressions
- Tips for Formatting Longer Criteria Across Multiple Lines
- Using String Substitution for Literal Values into a View Criteria Expression Used Only Once
- Using Custom Bind Variables for View Criteria Used Multiple Times
- Using View Criteria to Query Case-Insensitively
- Limitations of View Criteria Filter Expressions
- Finding Rows in a Child Rowset Using findRowsMatchingCriteria
- Using a Predefined View Criteria on a Standard Object
- Accomplishing More with Less Code
- Embracing Null-Handling in Conditions
- Embracing Null-Handling in Loops
- Understanding Groovy's Null-Safe Comparison Operators
- Using Functions as Objects with Closures
- Working More Cleverly with Collections
- Using Optional Method Arguments
- Simplifying Business Logic Queries
- Creating a New Object
- Updating an Existing Object
- Permanently Removing an Existing Object
- Reverting Changes in a Single Row
- Understanding Why Using Commit or Rollback In Scripts Is Strongly Discouraged
- Using the User Data Map
- Referencing Information About the Current User
- Using Aggregate Functions
- Understanding When to Configure Field Dependencies
- Enforcing Conditional Updateability of Custom Fields for Web Service Access
- Implementing Non-Formula Field Changeable Only From Script
- Understanding When Field Default Value Expressions Are Evaluated
- Understanding the Difference Between Default Expression and Create Trigger
- Deriving Values of a Field When Other Fields Change Value
- Setting Invalid Fields for the UI in an Object-Level Validation Rule
- Determining the State of a Row
- Understanding How Local Variables Hide Object Fields
- Invoking Web Services from Your Scripts
- Accessing the Display Value of the Selected Item(s) in a List Field
- Formatting Numbers and Dates Using a Formatter
- Working with Field Values Using a Parameterized Name
- Determining the Object Type of a Row
5 Best Practices for Groovy Performance
- Search Using at Least One Indexed Field
- Explicitly Select Only the Attributes You Need
- Test for Existence by Retieving a Single Row
- Avoid Using newView() Inside a Loop
- Set Field Values in Bulk
- Avoid Revalidating Known Valid Data
- Use Left Shift Operator To Append to Lists
6 Understanding Common JBO Exceptions in Groovy Scripts
- JBO-25030: Detail entity X with row key Y cannot find or invalidate its owning entity
- JBO-26020: Attempting to insert row with no matching EO base