Sometimes, you need to create a report that is fairly complex in detail, requiring data from various sources across Kademi. This is where the powerful Custom Indexed Fields come into play.
When the index is reindexed, we can execute code to pull data from another table or any other source and store it on the search index entry.
This means that if part of the required data is stored elsewhere in Kademi, when it's time to build the query, you only need to query the database once (assuming all required data is on the same index).
It's incredibly simple, and you can do it like so. This example demonstrates storing the most recent date a user completed training on a module status. This ensures that even if the module expires or renews, you can reference the last time they completed it. This works by accessing the learningLog database, which stores a permanent entry of any training data.
The code is as follows:
queries.addAppIndexedField("learning", "mostRecentCertificationDate", "keyword", false, "generateCurrentCertificationDate"); function generateCurrentCertificationDate(contentItem, updatedObject) { learningLogTable1 = services.criteriaBuilders.get("learningLog") .eq("profile", updatedObject.profile) .eq("action", 'c') .eq("moduleStatusId", formatter.toLong(updatedObject.id)) .sortDesc("id") .executeSingle(); if (formatter.isNotNull(learningLogTable1)) { return learningLogTable1.reqDate; } else { return null; } }
And it should look like this in the index, You will notice that the mostRecentCertificationDate can differ from the created date of the Module Status
You can then use this field in any report that references this search index.