- 09 Feb 2023
- 1 Minute to read
- Print
- DarkLight
How to Validate Reference Fields on the Enrollment Record
- Updated on 09 Feb 2023
- 1 Minute to read
- Print
- DarkLight
Validate that Cross Field References on Enrollments Exist
- Open the Consumer Application in Studio and go to the Advanced Menu
- Find the application's Enrollment Record Mapping, then click the kabob menu and select Details
- 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.
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.
Click the ADD button to create a new Field Mapping
Set the Target Field Name to recordStatus
Set the Value Type to Expression
Keep the On Create and On Update checkboxes checked
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; }
Click Save
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.