/
Flatten List of Items
© 2025 IQVIA - All Rights Reserved
Flatten List of Items
Summary
This is actually two methods which can take a list items sharing a name prefix, and return a single string value reflecting their selection status.
Volunteer record demographics import is the highlighted use case. Please see the walkthrough showing how these methods can be used and tested. Note that as written this method only looks at boolean data types.
Form Setup
The ITEM_NAME_PREFIX needs to be updated to reflect a shared prefix among the item data of interest.
Formal Expression
Method #1
var ITEM_NAME_PREFIX = "DM Race -";
var result = "";
var selectedRaces = findTrueItemsWithNamePrefix(formJson, ITEM_NAME_PREFIX);
// logger('selectedRaces size '+)
if (selectedRaces.length == 1) {
result = selectedRaces[0];
} else if (selectedRaces.length > 1) {
result = "Multiple";
}
return result;
function findTrueItemsWithNamePrefix(formJson, itemNamePrefix) {
var matchingItems = [];
var itemGroups = formJson.form.itemGroups;
if (itemGroups && itemGroups.length) {
for (var i = 0; i < itemGroups.length; i++) {
var itemGroup = itemGroups[i];
var items = itemGroup.items;
for (var j = 0; j < items.length; j++) {
var item = items[j];
if (item.dataType == "boolean" && item.value == "true"
&& itemNamePrefix !== null && item.name.indexOf(itemNamePrefix) === 0) {
matchingItems.push(item.name.split('-')[1]);
}
}
}
}
return matchingItems;
}
Method #2
var ITEM_NAME_PREFIX = "DM Race -";
var result = "";
var selectedRaces = findTrueItemsWithNamePrefix(formJson, ITEM_NAME_PREFIX);
// logger('selectedRaces size '+)
if (selectedRaces.length > 1) {
result = selectedRaces.join(",");
}
return result;
function findTrueItemsWithNamePrefix(formJson, itemNamePrefix) {
var matchingItems = [];
var itemGroups = formJson.form.itemGroups;
if (itemGroups && itemGroups.length) {
for (var i = 0; i < itemGroups.length; i++) {
var itemGroup = itemGroups[i];
var items = itemGroup.items;
for (var j = 0; j < items.length; j++) {
var item = items[j];
if (item.dataType == "boolean" && item.value == "true"
&& itemNamePrefix !== null && item.name.indexOf(itemNamePrefix) === 0) {
matchingItems.push(item.name.split('-')[1]);
}
}
}
}
return matchingItems;
}
, multiple selections available,
Related content
Out Of Range Item Data in Form
Out Of Range Item Data in Form
More like this
Populate Item Barcode(s) or Sample Transfer Barcode(s) from the same Form into a Specific Item
Populate Item Barcode(s) or Sample Transfer Barcode(s) from the same Form into a Specific Item
Read with this
Find Item Value From Same Study Event
Find Item Value From Same Study Event
More like this
Data Quality Checks Dashboard Component
Data Quality Checks Dashboard Component
Read with this
collectCompletedFormData
collectCompletedFormData
More like this
Out Of Range Item Data in Item Group
Out Of Range Item Data in Item Group
More like this
Exported and Printed Copies Are Uncontrolled