Deep dive: Generate repeatable groups from associated records
| Warning | Work in progress! We are in the process of updating the information on this page. Subject to change. |
In this guide, we will demonstrate how a custom JavaScript function can be used to generate as many repeatable groups as there are associated records of the parent. This use case showcases a scenario where we open a questionnaire directly from a work order, with as many repeatable groups as there are associated work order incidents. These repeatable groups are automatically generated based on the number of related incidents. Each group contains a lookup question filled with an incident.
Prerequisites
- Workorder lookup question.
- Repeatable group with workorder lookup incident.
Script
Define your own questions and question groups accordingly.
const CHECKLIST_STEP_GROUP_NAME = "group";
const WO_INCIDENT_ENTITY_NAME = "msdyn_workorderincident";
const WO_INCIDENT_LOOKUP_QUESTION_NAME = "work-order-incident";
const WORKORDER_LOOKUP_QUESTION_NAME = "resco_workorder";
If you use a case that requires other tables, e.g., accounts and assets, rewrite the code.
Functions explanation
generateQuestionnaireContent - loads the questionnaire context, initializes loadTemplateGroupId and then generateGroups loadTemplateGroupId - finds id of the group we want to repeat generateGroups - initialize LoadWorkorderIncidents and repeatNext, by invoking repeatGroup we already have two instances of group therefore -2 LoadWorkorderIncident - fetches and returns dynamic entities with incidents repeatNext - generates as many repeatable groups as the checklist length and initializes setGroupValues. setGroupValues - fills in the questions from the incident into already created repeatable groups.