Checking Frontmatter variable if contains/isin s specific key word list

Checking Frontmatter variable if contains/isin s specific key word list

Hi guys,

i need your help by editing/running a dataviewjs query.
Several trials didn’t help and googling didn’t help me as well in that case.

My Setup:

I’m using contact markdown files with standarized frontmatter variables and project overview markdown files where all realated notes and KPIs, stakeholders and so on linked to:

Franz.md (contact file)



link: -
name: Franz
mobil: 1234
mail: [email protected]
role:
department:
company:
adress:
phone:
tags:

  • contacts
    priority: 5
    projects_involved:
  • project1
  • project2
    status: active

Franz

foo bar


project1.md



created: 2023-01-24 09:13
aliases: “2023-01-24 09:13:37:62”
modified: NaN
project: project1
type: project
status: active
tags:

  • foo
  • bar
    priority:

Project 1

stakeholders

dv.table(
	["name", "department","phone", "mail"],
	dv.pages()		
	.where(p => p.project_involved.contains( 
			dv.current().project)
			)
	.map(
		p=>[
			p.file.link,
			p.department,
			p.phone,
			p.mail
			]
		)
)

The upper code don’t work and returns the following error message
“”"
Evaluation Error: TypeError: Cannot read properties of undefined (reading ‘contains’)
at eval (eval at (plugin:dataview), :4:33)
at Array.filter ()
at Proxy.where (plugin:dataview:9418:39)
at eval (eval at (plugin:dataview), :4:3)
at DataviewInlineApi.eval (plugin:dataview:19734:16)
at evalInContext (plugin:dataview:19735:7)
at asyncEvalInContext (plugin:dataview:19745:32)
at DataviewJSRenderer.render (plugin:dataview:19766:19)
at DataviewJSRenderer.onload (plugin:dataview:19350:14)
at DataviewJSRenderer.e.load (app://obsidian.md/app.js:1:864580)
“”"

My plan is to show all responsible stakeholders related to that project based on the frontmatter variable “projects_involved” of the contact markdown file.
Due to the fact, that one contact can involved in more than one project, i have to use a function like “contains” or “isin”. → “is a item in in projects_involved equal to project”

Can somebody help me?

King regards,

raymanzarek

Things I have tried

What I’m trying to do

There might be more errors, then the one I’ll mention, but first of all please envlise all of your markdiwn, code blocks and queries in four backticks, ````, in the forum post, as that shows us what you’ve actually written in your notes.

Ok, you need at least to do p.project_involved?.contains(...) to allow for notes not having that field defined.

I think I see some other errors too, but can’t tell for sure before I see your markdown properly formatted within four backticks.

[quote=“raymanzarek, post:1, topic:53011”]

Thanks for your reply.
As you remarked, attached the markdown file contents with 4x`

Franz.md (contact file)

---

link: -
name: Franz
mobil: 1234
mail: [[email protected]](mailto:[email protected])
role:
department:
company:
adress:
phone:
tags:
- contacts
priority: 5
projects_involved:
- project1
- project2
status: active

---

# Franz

foo bar

project1.md (Project File):


---

created: 2023-01-24 09:13
aliases: “2023-01-24 09:13:37:62”
modified: NaN
project: project1
type: project
status: active
tags:
- foo
- bar
priority:

---

# Project 1

## stakeholders

```
dv.table(
	["name", "department","phone", "mail"],
	dv.pages()		
	.where(p => p.project_involved.contains( 
			dv.current().project)
			)
	.map(
		p=>[
			p.file.link,
			p.department,
			p.phone,
			p.mail
			]
		)
)
```

The upper code don’t work and returns the following error message
“”"
Evaluation Error: TypeError: Cannot read properties of undefined (reading ‘contains’)
at eval (eval at (plugin:dataview), :4:33)
at Array.filter ()
at Proxy.where (plugin:dataview:9418:39)
at eval (eval at (plugin:dataview), :4:3)
at DataviewInlineApi.eval (plugin:dataview:19734:16)
at evalInContext (plugin:dataview:19735:7)
at asyncEvalInContext (plugin:dataview:19745:32)
at DataviewJSRenderer.render (plugin:dataview:19766:19)
at DataviewJSRenderer.onload (plugin:dataview:19350:14)
at DataviewJSRenderer.e.load (app://obsidian.md/app.js:1:864580)
“”"

My plan is to show all responsible stakeholders related to that project based on the frontmatter variable “projects_involved” of the contact markdown file.
Due to the fact, that one contact can involved in more than one project, i have to use a function like “contains” or “isin”. → “is a item in in projects_involved equal to project”

Can somebody help me?

King regards,

raymanzarek

What happens when you change this to:

.where(p => p.project_involved?.contains( 
			dv.current().project)
			)

Note the extra question mark in there…

Thanks for your reply.

I changed the

.where(p => p.project_involved?.contains( 
			dv.current().project)
			)

The query shows no error message, but without any results

What does the questionmark ? do after the variable of the pages?

What if you use projects_involved in both places, and not only project_involved? :wink:

The question mark allows javascript to bail out gracefully, if (or when) the field doesn’t exist. Like when you check all other files which are not supposed to match (and when you’ve got a small, but crucial typo).

1 Like