[DONE] Multi-select fields injects flat array instead of grouped array (I think it is a bug)


I’m running into an issue where I’m trying to generate an HTML table in calc field as a summary from multiple related items. Everything works except for the Multi Select field in a related item.

Here’s the setup: const entitlements = @All of Entitlements with nulls ;

One field from the related item - Entitlements - is a multi-select fields. So in each related item, this particular field might have one value, two values or more.

so I would expect the following to be an array of arrays.

const entitlements = @All of Entitlements with nulls ;

Instead it is a flat single array.

For example, the output looks like:

Product 1: Apple,Mango,Orange,Apple, Mango
Product 2: Apple,Mango,Orange,Apple, Mango
Product 3: Apple,Mango,Orange,Apple, Mango

Instead of what I expect:

Product 1: Apple,Mango,
Product 2: Orange
Product 3: Apple, Mango

The number of entitlements per product can vary, so slicing the array by a fixed size isn’t reliable. It seems like Tape isn’t grouping the entitlements per row/product when using @All of ... with nulls.

Code from calc:

const formatDate = d => {
 const date = new Date(d)
 return isNaN(date) ? '' : date.toDateString()
}
// collect all fields (Tape injects them)
const names = @All of Name with nulls
const creation = @All of Creation Date with nulls
const entitlements = @All of Entitlements with nulls
let html = ''

html += '<table style="border-collapse:collapse;font-family:system-ui,Arial,Helvetica,sans-serif;font-size:12px;width:100%;border:1px solid #ccc;">'
html += '<thead></thead><tbody>'

const total = Math.max(
 names.length, creation.length, entitlements.length
)

for (let i = 0; i < total; i++) {
 html += '<tr>'
 html += `<td style="padding:4px;border:1px solid #ddd;">${names[i] || ''}</td>`
 html += `<td style="padding:4px;border:1px solid #ddd;">${formatDate(creation[i])}</td>`
 html += `<td style="padding:4px;border:1px solid #ddd;">${entitlements || ''}</td>`
 html += '</tr>'
}
html += '</tbody></table>'
html```
4 Likes

Hi @Thaha,

thanks for the report and your patience. We looked into this, and indeed the behaviour diverged from what some known legacy systems have used in the past. As you stated, a grouped array of arrays for the “With nulls” token in multi category fields is the expected behavior and allows distinguishing from which reference the values originate.

We deployed a fix today. However, in order to avoid breaking existing scripts, the new behaviour will only apply after you have re-created the script reference. So you would need to remove the token from your calculation field script once, save the script and readd it afterwards. You should then be able to confirm the fix on your end - we just did using our own testing scenario.

Let us know how it works and whether this fully solves your use case.

Cheers &
Happy Sunday
Tim