How to Validate Reference Fields on the Enrollment Record
  • 09 Feb 2023
  • 1 Minute to read
  • Dark
    Light

How to Validate Reference Fields on the Enrollment Record

  • Dark
    Light

Article summary

Validate that Cross Field References on Enrollments Exist

  1. Open the Consumer Application in Studio and go to the Advanced Menu
  2. Find the application's Enrollment Record Mapping, then click the kabob menu and select Details
  3. Scroll down to the Field Mappings and check to see that there isn't already a mapping for Target Field Name of recordStatus for the Create, Update events.
Note:

recordStatus mappings on Create, Update events are a quick and easy way to filter out records that do not meet specific criteria that's defined in the mapping expression.

  1. Click the ADD button to create a new Field Mapping

  2. Set the Target Field Name to recordStatus

  3. Set the Value Type to Expression

  4. Keep the On Create and On Update checkboxes checked

  5. Paste the following code into the Value input area:

    function() {
      const userKey = SRC.user[0];
      const classKey = SRC.section[0];
      const orgKey = SRC.org[0];
    
      var enrollmentUser = SRC.getRecord("user",userKey);
      var enrollmentClass = SRC.getRecord("section",classKey);
      var enrollmentOrg = SRC.getRecord("org",orgKey);
    
      var error = 'no';
    
      if (!enrollmentUser) {
        LOGGER.warn("unable to find user record with recordKey " + userKey + " in enrollment " + SRC.recordKey);
        error = 'yes';
      }
    
      if (!enrollmentClass) {
        LOGGER.warn("unable to find class record with recordKey " + classKey + " in enrollment " + SRC.recordKey);
        error = 'yes';
      }
    
      if (!enrollmentOrg) {
        LOGGER.warn("unable to find org record with recordKey " + orgKey + " in enrollment " + SRC.recordKey);
        error = 'yes';
      }  
    
      if (error == 'yes') {
        LOGGER.warn("skipping enrollment record with recordKey " + SRC.recordKey);
        return 'delete';
      }
    
      return null;
    
    }
    
    
  6. Click Save

  7. The next time the Enrollment mapping job is run for the consumer, check in the Data Explorer for the Consumer Application -enrollment records to verify the expected outcome from this mapping function.

This expression, when mapped to the recordStatus on Create and Update events on a consumer application, verifies that the User, Class and Org references on each enrollment record exist in the ID Hub else, the record is not included in the output for the consumer application.


Was this article helpful?


ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence