Simple to Advanced Queries - Related Tasks

Hey-oh! :wave:

I have the below query:

### ๐Ÿš€ Related Tasks
#+BEGIN_QUERY
{
:query (and [[ACME Org]] (task NOW LATER DOING TODO WAITING))
:breadcrumb-show? true
:collapsed? false
:table-view? false
:group-by-page? true
}
#+END_QUERY

This query does work and I have it on each individual customer page within LogSeq. However it requires me to update the page being referenced on each one. Since I have this as a template, Iโ€™d love to leverage the ?current-page built-in variable since the page name matches what I want. Iโ€™ve tried to incorporate it in a simple query (as above) but with no luck.

So, iโ€™ve been trying to use a new advanced query for this (see below) from the docs, but for some reason I am not getting anything backโ€ฆ

### ๐Ÿš€ Related Tasks
#+BEGIN_QUERY
{
:query [:find (pull ?b [*])
       :in $ ?current-page
       :where
       [?p :block/name ?current-page]
       [?b :block/refs ?p]
       (task ?b #{"TODO" "LATER" "NOW" "WAITING" "DOING"})]
:inputs [:current-page]
}
#+END_QUERY

Any ideas what could be going on here? TYIA!

Could you share some example blocks that you would like to get back?

Certainly!

They are all Tasks which would reside on the daily Journal pages or directly on the customer page where this query is located. All tasks may be referenced by a parent block as well.

Sample Journal page

## Scratchpad
	-
	-
- ## Meetings
	- [[Customer B]] - Setup & Configure #SSO/EntraID #meeting
		- **Participants:** 
		- **Topics:**
			- Introductions / Agenda
			- #AzureBlob - Follow-up from last week?
				- How has the mount and automation with Partner A been working?
				- 3 other partners on Files.com currently
			- #SSO / #EntraID
				- SCIM
			- Next Steps
		- **Blockers:**
			-
		- **Decisions:**
			-
		- **Action Items:**
			- TODO [#A] Update [[Customer C]] on renewal discussions
		- **Notes:**
			- [files.com/Azure SSO via SAML](https://www.files.com/docs/user-accounts/sso-single-sign-on/azure-ad-sso#azure-sso-via-saml)
			- ==Reminder:== Need break glass account
			-
	- Check-in w/ [[EL]]
	  collapsed:: true
		-
- ## Tasks
	- DONE [#B] Call [[Customer A]] at [[Organization A]] to introduce myself as their SA #call
	  collapsed:: true
	  SCHEDULED: <2024-08-19 Mon>
		- No answer, left vmail
		- Sent follow-up email 
	- DONE [#B] Call [[Customer B]] at [[Organization A]] to introduce myself as their SA #call
	  collapsed:: true
	  SCHEDULED: <2024-08-19 Mon>
		- Customer answered
		- Would like to understand more about the product
		- Only concerns have been previously with SmartFile
			- Slowness
			- Disconnects
		- Looking forward to meeting!
		- Sent follow-up email with link to schedule meeting
	- DONE [#A] Prep for meeting w/ [[Customer C]] at [[Organization B]] today at 1pm
	  SCHEDULED: <2024-08-19 Mon>
	  :LOGBOOK:
	  CLOCK: [2024-08-19 Mon 09:49:43]--[2024-08-19 Mon 10:04:14] =>  00:14:31
	  :END:
	- DONE [#C] Professional Development - [Datalog - Parameterized queries](https://www.learndatalogtoday.org/chapter/3)
	  SCHEDULED: <2024-08-19 Mon>
	  :LOGBOOK:
	  CLOCK: [2024-08-19 Mon 09:49:36]--[2024-08-19 Mon 09:49:42] =>  00:00:06
	  CLOCK: [2024-08-19 Mon 10:04:27]--[2024-08-19 Mon 11:41:13] =>  01:36:46
	  :END:
	- TODO [#C] Professional Development - [Datalog - More Queries](https://www.learndatalogtoday.org/chapter/4)

Sample Customer Page

icon:: ๐Ÿข
tags:: Customers, myCustomers
alias:: ACME

- **Links**
  [CRM](xxxxx)          [+CustomerSuccess](xxxxx)          [Website](https://files.com/)           [LinkedIn](https://www.linkedin.com/company/xxxxx)
- **Business Use Case**
  *...*
- **Partners & Technologies**
  #EntraID #AzureBlob
- ### ๐Ÿ”Ž Account Maintenance
	- Migrated from SmartFile on [[2024-07-29]]
	-
- ### ๐ŸŽ‰ Increased Usage Wins
	- ...
- ### ๐ŸŽฏ Customer Opportunities
	- [[ACME/Azure SSO]] {{renderer :todomaster}}
		- TODO Using SCIM?
		- TODO Discuss User/Group Management
			- TODO Are User Groups ready in Entra ID?
			- TODO Have we replicated them in Files.com?
		- TODO Do we have a break-glass user account?
		- TODO Configure Entra ID SSO Integration
		- TODO Validate Configuration
	- [[ACME/Email Inboxes]] {{renderer :todomaster}}
	  collapsed:: true
		- TODO Additional Discovery Needed
		  id:: 66bf9ef1-9c6b-416d-a36d-c8b80333ae7a
		  *Currently SMB customers are emailing CSV's to Account Directors whom forward it to the Data Team to manually upload into the Data Lake.*
	- โœ… **DONE**
	  collapsed:: true
		- [[ACME/Azure Blob]] {{renderer :todomaster}}
		  collapsed:: true
			- DONE Determine Permissions Required for Azure Blob
			- DONE Create Azure Blob as Remote Server & Validate
			- DONE Determine & Create Mount for Azure Blob
			- DONE Create Permissions Fence
			- DONE Create Automation for ==Partner A==
- ### ๐Ÿ’ก Feature Requests
	-
- ### ๐Ÿž Issue Tracking
	-
- ### ๐Ÿš€ Related Tasks
  #+BEGIN_QUERY
  {
  :query (and [[ACME Corporation]] (task NOW LATER DOING TODO WAITING))
  :breadcrumb-show? true
  :collapsed? false
  :table-view? false
  :group-by-page? true
  }
  #+END_QUERY
- ### ๐Ÿชฌ Identified Features
  #+BEGIN_QUERY
  {
     :query [:find ?name
     :in $ ?current-name %
     :where
       [?current :block/name ?current-name]
       [?meeting :block/name "meeting"]
       [?root :block/refs ?current]
       [?root :block/refs ?meeting]
       (ancestor ?root ?b)
       [?b :block/refs ?ref]
       [?ref :block/properties ?props]
       [(get ?props :type) ?type]
       [(= ?type "feature")]
       [?ref :block/original-name ?name]
   ]
   :inputs [:current-page
     [
       [
         [ancestor ?a ?b]
         [?b :block/parent ?a]
       ]
       [
         [ancestor ?a ?b]
         [?parent :block/parent ?a]
         (ancestor ?parent ?b)
       ]
     ]
   ]
  }
  #+END_QUERY
- ### Notes
	- ...

As far as references, I always โ€œtag/referenceโ€ the customer organization page either in the same block as the TODO or in a parent block in the case of a meeting logged on the Journal page. TODOโ€™s on the Customer page directly are usually part of a active or upcoming project/opportunity.

Customer pages are normal pages, no special type:: configured. People however have a page type:: person and each โ€œperson pageโ€ is also linked to their Organization via the Organization:: [[ACME Corporation]] custom property.

Thank you again and please let me know if there is anything further I can provide to aid in this.

The tricky part in your query is that attribute :block/refs should be :block/path-refs , because the reference is placed in an ancestor block. This is how references are treated in simple queries.

1 Like

Thank you, again!

Very much appreciate that precise solutions. Love learning this new tool!