Templater Suggester query

What I’m trying to do

Hello,

instead of manually set the values for the templater suggester command, I’d like to use a query.

The starting point are e.g. 3 project files:

project_1.md
---
assigned: [Peter, Paul]
---

project_27.md
---
assigned: [Mary, Paul]
---

project_16.md
---
assigned: [Paul]
---

via DV I can flatten a list (table) to output eyery person:

Things I have tried

```dataview
TABLE WITHOUT ID
assigned + " (" + length(rows.file.link) +")" AS Asgd
FROM ""
WHERE assigned
FLATTEN assigned
Group by assigned
SORT length(rows.file.link) DESC
```

but how can I achieve this in TEMPLATER via the suggester command, so that I only get a list of the assigned ones, and most of all: only one person per row?
This thing seems a bit more difficult than reading in a list of files…

1 Like

Thanks for following up. Rather than edit the title and adding an emoji, can you please reply with your solution, and then mark it as “Solution”?

@rigmarole Thanks for following up. Rather than edit the title

oh, yes of course, thats why there is no solution in edit… :grinning:
thank you for the hint.

edit
well, I figured it out over discord, but maybe someone else will find it helpful and I can also do something good for a change :smirk:

```
const people = (await app.plugins.getPlugin("dataview").api.tryQuery(`
TABLE 
assigned AS M
FROM "Projects"
WHERE assigned 
FLATTEN assigned 
Group by assigned 
SORT length(rows.file.link) DESC
`)).values
const selectedPerson = await tp.system.suggester(item => item, people, true, "Placeholder...")

```
1 Like

Quick question: is this code wrapped in ```dataviewjs ? Trying to get to work…thanks !

no, the code is placed in the template, just as it stands above, of course you have to set it within the commands <%* %>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.