Validate Reference Fields on the Enrollment Record

RapidIdentity Platform Documentation

Solution
Application
Content Type
Technical Documentation
Utilities & Services
ft:locale
en-US

Verify cross-record references on enrollment records exist before including the enrollment record in the output for the consuming application.

Best Practice:
  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 verify there isn't already a mapping for Target Field Name of recordStatus for the Create, Update events
  4. Click the ADD button to create a new Field Mapping
  5. Set the Target Field Name to recordStatus
  6. Set the Value Type to Expression
  7. Keep the On Create and On Update checkboxes checked
  8. 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;
                            }
  9. Click Save
  10. 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
Note: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.