Configure Groovy Script Based Set Master Record Rules

In this example, you will learn how to create a set master record rule to select the master record in a resolution request, with different logic depending on whether the resolution request is merge request or a link request.

The logical requirements of the scenario are as follows:

  • If the resolution request is a merge request:
    • Records integrated with RNOW source system are the top priority to be master record.
    • If multiple records are present from a prioritized source system, use the most recently updated record as the tiebreaker.
    • If no RNOW-integrated records are present in the merge, take whatever record had been designated as master by the upstream process.
  • If the resolution request is a link request:
    • The record with the highest Customer Profile Quality Score should be selected as the master record.
    • If multiple records are tied for the highest Customer Profile Quality Score, use the most recently updated record as the tiebreaker.
    • If none of the records in the link request have been assigned a Customer Profile Quality Score, take whatever record had been designated as master by the upstream process.

Steps to Perform

  1. Enable Groovy Scripts to select master records:

    1. In the Setup and Maintenance work area, go to the following:

      • Offering: Customer Data Management

      • Functional Area: Customer Hub

      • Task: Manage Customer Data Management Options

    2. In the Merge Behavior section, select the Select master record using groovy scripts option for the Master Record Selection field.

  2. Create an Application Composer sandbox. Refer to the Create an Application Composer Sandbox topic for the steps.

  3. Populate the sample script in the AccountSetMaster template:

    • Navigate to Common Setup and click Data Quality Rules.

    • Click AccountSetMaster.

    • Copy and paste the code given in the Sample Code section in the Edit Data Quality Rules page.

    • Click Save and Close.

  4. Test the code. Refer to the Test the Survivorship and Agreement Rules Configuration topic to test the code.

  5. Deploy the Code, after you're satisfied with the results of the Set Master Record Rules. See the topic: Deploy the Survivorship and Agreement Rules Configuration.

What the Sample Script Does

The script begins by calling the getRows() input function to access the records in the resolution request. After initializing additional variables, the script calls getAttribute("ResolutionType") to determine what type of resolution request is being processed.

If the Resolution Type is MERGE, the script loops through the records in the resolution request to inspect which source system reference assignments exist for each record. When a record with an RNOW source system reference is found, the row is added to the list of records having the given source system reference assignment.

Once all the rows in the resolution request have been tested for their source system reference values, the script tests whether any records from the prioritized source system reference were found. If records are found in the top priority list, they're tested by last updated date. Then the most recently updated record having the highest priority source system reference is designated to become the master record.

If the Resolution Type is LINK, the script loops through the records in the resolution request to inspect each record’s Customer Profile Quality Score value. Each record’s value is compared to the highest value found so far, and if the current row has a higher value than the highest value found so far, that row is promoted to become the master record of the link set.

Finally, the script calls the selectMaster() output function to designate the master record. If a top-priority or second-priority record was identified earlier in the script, that record is provided to the selectMaster() function. If no priority record was identified in either the Merge or Link execution blocks, then the default master record specified by the upstream process will be retained as the master record for the resolution request.

Sample Code

try {
  def requestRows = getRows();
  def rowMaster = false;
  def osrMap = ['RNOW': []];
  def rowDefaultMaster = getMaster();
  def iHighestAccountScore = 0;
  def resolutionType = getAttribute("ResolutionType");

  if (resolutionType == "MERGE") {
    for (row in requestRows) {
      def osrRows = row.getAttribute("OriginalSystemReference");
      osrRows.reset();
      while (osrRows.hasNext()) {
        def osrRow = osrRows.next()
        if (osrRow.OrigSystem == "RNOW") {
          osrMap['RNOW'].add(row);
        }
      }
    }

    if (rowMaster == false && osrMap['RNOW'].size() > 0) {
      rowMaster = osrMap['RNOW'][0];
      for (row in osrMap['RNOW']) {
        if (row.LastUpdateDate > rowMaster.LastUpdateDate) {
          rowMaster = row;
        }
      }
    }
  }

  if (resolutionType == "LINK") {
    for (row in requestRows) {
      if (nvl(row.AccountScore, 0) > iHighestAccountScore) {
        rowMaster = row;
        iHighestAccountScore = row.AccountScore;
      }

    }

  }

  if (rowMaster) {
    selectMaster(rowMaster);
  } else {
    selectMaster(rowDefaultMaster);
  }

} catch (Exception e) {
  def sMsg = "Exception in Account Set Master: " + e.getMessage();
  println(sMsg);
}