© 2024 IQVIA - All Rights Reserved

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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.

INSERT VIDEO HERE

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

  • No labels