Jump to content

Deep dive: Generate repeatable groups from associated records

From Resco's Wiki
Revision as of 10:38, 19 November 2025 by Marek Rodak (talk | contribs)
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";

Execution order

These are the main functions used in the script:

generateQuestionnaireContent
  • loads the questionnaire context
  • Initializes loadTemplateGroupId and generates groups
loadTemplateGroupId
  • finds the ID of the group we want to repeat
generateGroups
  • Initializes LoadWorkorderIncidents and repeatNext, by invoking repeatGroup, we already have two instances of group, therefore we subtract 2.
LoadWorkorderIncident
  • Fetches and returns dynamic entities with incidents.
repeatNext
  • generates as many repeatable groups as there are incidents
  • initializes setGroupValues.
setGroupValues
  • fills in the questions from the incident into already created repeatable groups.