Create Suggester List based on inline data field

I think it would be a whole lot easier to trigger a Dataview query from within the templater script, and then use the output of that to populate your suggester list. The way you script is setup currently, you’re reading through the entire vault searching for potential candidates. If you used a query you would only scan through the metadata, and you’ll get the added benefit of getting all fields (frontmatter or inline).

Here is a mockup which should get you started. You need to change the query according to your setup, and you’ll need to extract and use the relevant information later on in your template.

<%*
const dv = app.plugins.plugins.dataview.api

const result = await dv.query(`
TABLE file.name, title, email, cell
FROM "ForumStuff/f65/f65535"
WHERE entity = "CompanyA"
  AND file.link
`)

if (result.successful ) {
  console.log(result.value.values)
   const selectedPerson = await tp.system.suggester(
     r => r[1], result.value.values)
   tR += JSON.stringify(selectedPerson)

} else
  dv.paragraph(`~~~~\n${ result.error }\n~~~~\n`)
%>

There are two major tricks used in this code. Firstly, we use the Dataview query to populate the result into result.value.values. So test the query, and make sure it returns all the needed information for later processing.

Secondly, when doing the suggester, we present the entire array of resulting values as the second parameter, aka result, and use dereferencing of this result array to pick out what to show in the _first_parameter. Put another way the first parameter says that for each of the values within result.value.values (now called r) , use the second column from the query (aka r[1]) as the value to present in the suggester. When you select something now it’ll return that value of the result.value.values list.