Configure Groovy Script Based Set Attribute Value Rules

In this example, you will learn how to create a set attribute value rule to override the standard attribute source confidence-based survivorship processing with groovy script based on the classification code assignment of the records.

The logical requirements of the scenario are as follows:

  • If the merge contains a record that has been classified as OFN Category One account, use that OFN Category One record's value for a set of key fields regardless of the attribute source confidence score.

  • If multiple rows in the merge have been classified as OFN Category One, use the attribute values from the most recently updated row.

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 under the Duplicate Resolution Options tab, select the following options:

      • Select either Use source confidence with newest record as the tie breaker or Use source confidence with oldest record as the tiebreaker for the Attribute Selection Type field.

      • Select Yes for the Add Groovy to Attribute Selection field.

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

  2. Populate the sample script in the AccountSetAttribute template:

    1. Navigate to Common Setup and click Data Quality Rules.

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

    3. Click Save and Close.

  3. Test the code. Refer to the Test the Survivorship and Agreement Rules Configuration section to test the code.

  4. Deploy the code after you're satisfied with the results of the attribute value rules, you can. 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 merge request. Next, the script loops through each of the row records and accesses its Code Assignment collection. The script then loops through the code assignments to test whether the specified code assignment value is present. When a row having the specified code assignment is identified, the row is copied into an array of prioritized records for subsequent processing.

Once all the rows in the merge request have been tested for their code assignment values, the list of prioritized records is sorted based on the records' last update date. Finally, the script identifies the most recently updated row having the specified code assignment value. After this row is identified, the script calls the selectAttribute() output function to designate that priority row as being the attribute value source for a set of defined attributes.

Sample Code

try {
  def rowDuplicates = getRows();
  def rowPriorities = [];
  def exceptionAttributes = ['BusinessScope', 'CeoTitle'];
  def CAs;
  def CAi;
  for(row in rowDuplicates){
    CAs = row.getAttribute("CodeAssignment");
    if(CAs){
      for(CA in CAs){
          CA.reset();
          while(CA.hasNext()) {
            CAi = CA.next();
            if(CAi.ClassCategory == "OFN" && CAi.ClassCode == "OFN1") {
              rowPriorities.add(row);}
          }
       }
    }
  }

  if(rowPriorities.size()){
    def rowPriority = rowPriorities[0];
    for (row in rowPriorities){
      if (row.LastUpdateDate > rowPriority.LastUpdateDate){
        rowPriority = row;}
    }

    for (a in exceptionAttributes){
      selectAttribute(a, rowPriority);
    }
  }
}

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