So, I’m hitting a stumbling block while trying to pull the number of values in an array.
I have a number of fields that I’m using as inline data for notes that I’m referring to as tasks.
My issue is, sometimes the RelatedTo filed contains one value, no value, or multiple values. almost always the values are links to other notes.
My trying to run a dataview query that will give me the “count” of the number of entries in that field. The only way I can find to do that is with length(), but that only works with arrays. So…
If there are no entires, it gives me a null… which I can deal with.
If there are 2 entries, it gives me 2
However, if there is 1… it errors and doesn’t show ANY of the data for that file.
Can anyone offer some help on how to query it correctly.
BTW… the idea is to develop a priority scoring system where by the distance from the due date, the last modified time, the task priority and how many other things it is related to all contribute to a scoring priority of the task to see which ones require more attention.
Yep, I’ve run into this issue too. The solution I came up with was to check the result and wrap it in an array if needed before I processed the result. But (as far as I know) that only works in a dataviewjs query.
Are you using a standard dataview query or a dataviewjs query?
I’ve been using a standard dataview query… more familiar with SQL than JS.
One question: how you put multiple values in an inline field?
Arrays in inline fields? I think that’s not possible!
You have some (false) results because you are using links… but if you use any other expression, you’ll see that the
length gives you the number of characters in the field.
For your intentions, you may need to create a field in YAML frontmatter with the correct syntax for an array:
example: [item 1, item 2, item3]
- item 1
- item 2
- item 3
You can put link arrays into Dataview inline fields. I know of two different ways:
Array1:: [[Untitled]], [[Untitled]], [[Untitled]]
And this report:
TABLE Array1, Array2
Produce this output:
Yes, good point! If there’s only one item it’s a raw object, not an array of one.
I can deal with that in a dataviewjs by checking the result, but I don’t know how to manage it within a regular dataview block.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.