int multiLevelPrepare(string questionnaire, [array data])
The multiLevelPrepare() function creates a subordinate case in the data set (Multi-Level Structure). Variables in the new case can be pre-assigned. This function is particularly useful in conjunction with a Multi-Level Listing.
Only one case with the specified data is created at a time, even if the function is called several times.
The function returns the case number (CASE) of the newly created case in the data record.
Usually, when using multiLevelPrepare(), you want to store some information (here, e.g., a name) for each subordinate case right away. For this, you use an internal variable that you create separately in the list of questions.
The following PHP code creates a subordinate case for each name in the list $names in the data record for the questionnaire personaldata and saves the name in the internal variable TX01_01.
foreach ($names as $name) { multiLevelPrepare('personaldata', ['TX01_01' => $name]); }
Below the PHP code, a question of the type Multi-Level Listing could be placed here, which allows the respective cases to be called up to enter the personal details. In the multi-level overview, you would again enter TX01_01 as the Variable for the title, so that the list shows all names.
In the subordinate questionnaire, the name can then be read via value('TX01_01') and, e.g., displayed with html().
// Display directly html('<h1>'.value('TX01_01').'</h1>'); // Display via placeholder, for example for further questions replace('%name%', 'TX01_01', 'response'); html('<h1>%name%</h1>');