© 2024 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.

https://vimeo.com/575093630/8d1ce313ef

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; }

 

Exported and Printed Copies Are Uncontrolled