Best Practices for Configuring Groovy Scripts for Link Requests

In this topic we discuss the best practices for configuring groovy scripts.

  • If you configure your implementation to use Groovy Scripts for linking, your duplicate resolution requests aren’t processed until a valid link management script has been deployed.
  • Link request processing may handle very large volumes of records, so groovy scripts should be as fast and efficient as possible. Avoid using newView() functions and web service calls unless absolutely necessary; and if necessary, assure that these types of operations will be fast and reliable.

Overview of Groovy Scripting Functions

Groovy Script support for configuring link requests is based on a specific set of functions that let you interact with the duplicate data records. These functions are of the following categories:
  • Functions that let you inspect the records in the link requests
  • Functions that let you define the result of the link request

These categories of specialized functions help you to process link requests using standard Groovy Script syntax and operations.

Input Functions

These functions provide the data that your logic evaluates. Generally, these functions are called at the beginning of your script to instantiate the information required to determine the proper link process outputs.

getObjectType()

This function lets you determine what type of party the link request is processing. This function returns PERSON or ORGANIZATION depending on which type of script calls it. It's generally not necessary to programmatically determine the object type because the scripts for Persons and Organizations are clearly differentiated as distinct functions within the Application Composer Data Quality Rules task. But there may be cases where it's helpful for logging or testing.

getMaster()

This function lets you access the data record that has been identified as the master record for the link request. The function is called without parameters and it returns a single Row object that contains the details of the master record. The following example shows a typical usage of this function:
Copy
 def rowMaster = getMaster();
  def masterName = rowMaster.getAttribute("OrganizationName");
  // etc...

getNonMasters()

This function lets you access the set of data records that have been identified as the non-master records for the link request. This function is called without parameters and it returns a list of row objects consisting of one list entry for each non-master record. It's important to note that the getNonMasters list isn't an ADF recordset object. ADF recordset functions such as reset() and first() don't work with the list. The following example shows a typical usage of this function:

Copy
 getNonMasters()
def rowNonMasters = getNonMasters();
   def nonmasterName;
   for (nonmaster in rowNonMasters) {
       nonmasterName = nonmaster.getAttribute("OrganizationName"); }
   // etc...

getRows()

This function lets you access the full set of customer records for the link request, which is the union of the master and non-master sets of rows. This function is called without parameters and it returns a list of row objects consisting of one list entry for each non-master record. Like the getNonMasters function, it's important to note that the getRows list isn't an ADF recordset object. ADF recordset functions such as reset() and first() don't work with the list. The following example shows a typical usage of this function:

Copy
def rowDuplicates = getRows()
   def duplicateName;
   for (duplicate in rowDuplicates) {
      duplicateName = duplicate.getAttribute("OrganizationName"); }
    // etc...

getSourceInfo(Row row,String attributeName)

This function lets you access information about which source system provided the current value of an attribute for a given master or non-master row. This function is called using the following parameters:

  • A row object for the non-master or master row of interest
  • The name of a source-confidence configured attribute

This function returns a source information record for the attribute in question. The structure of the source information record is as follows:

Attribute Definition Example
RecordId The party ID of the person or organization record referenced by the row object parameter. 300100184760397
AttributeName The name of the attribute parameter. OrganizationName
AttributeValue The current value of the attribute on the row. Pinnacle Systems
Source The code of the registered source system for the attribute value. RNOW
SourceConfidenceLevel The configured attribute source confidence value of the given attribute for the given source system. 90
SourceUpdateDate The time stamp when the person or organization record was updated with the current value. 1/24/2020 11:48:03 PM
The following example shows a typical usage of this function:
Copy
    def rowDuplicates = getRows();
    def rowSource;
    def bestSource;
    def bestValue;
    bestSource = getSourceInfo(rowDuplicates[0],"OrganizationName");
    for (row in rowDuplicates) {
      rowSource = getSourceInfo(row,"OrganizationName");
      if(rowSource.SourceConfidenceLevel > bestSource.SourceConfidenceLevel) {
        bestSource = rowSource;
      }  
    }
    bestValue = bestSource.AttributeValue;

Output Functions

Output functions create the final behavior of the based on the logic of a link process script. Generally, these functions are called at the end of the script after the data provided by the input functions has been evaluated with scripted logic.

selectMaster(Row row)

This function is used in Contact Set Master and Account Set Master scripts to specify which record from the link request should be selected as the master record. This function takes a data Row instance as its only parameter, and whatever row is passed to the function is the record that's retained as the master. The following example shows a typical usage of this function:
Copy
...
    def masterRow = rowDuplicates[0];
    for (row in rowDuplicates) {
      if row.LastUpdateDate > masterRow.LastUpdateDate {
        masterRow = row;
      }
    }
    selectMaster(masterRow);

Evaluating the Data

Once you have called the appropriate functions, your script needs to evaluate the data to determine the correct link result. This evaluation process uses standard Groovy Script operators and functions. For more information about Groovy scripts, see the Oracle Applications Cloud Groovy Scripting Reference guide.

Putting It Together

You can generally follow this pattern in groovy scripting:
  1. Call Input Functions
  2. Evaluate the Data
  3. Call Output Functions
Copy
/* Input Functions: call getRows() to initialize a list of the party records in the merge request and then
define a variable to designate the Master record and set it to the first record in the list of Rows */
    def rowDuplicates = getRows();  
    def masterRow = rowDuplicates[0]; 
/* Evaluate the Data: iterate through the list of records to determine if the current list item 
was more recently updated than whatever record has been designated the master.  If the current record was more recently updated, 
promote it to become the new Master */
    for (row in rowDuplicates) {
      if (row.LastUpdateDate > masterRow.LastUpdateDate) {
        masterRow = row; 
      }
    }
/* Call Output Functions: use the selectMaster() function to dictate which record from the merge set 
should become the master */
    selectMaster(masterRow);