Query to bring blocks from immediately preceding Hierarchy

Hi, I need help in a simple query that is driving me crazy :stuck_out_tongue:

I work in a company where we have a system for Service Orders.

A service order is it’s ID + ITEM ID, for example: 844746/2, where 844746 is the service order ID, and 2 is the Item ID.

I made a query to bring all notes from the service order, excluding the item:

  {
        :title [:h2 "Anotações - Ordem de Serviço"]
        :query
        [
          :find (pull ?b [*])
          :in $ ?current-page ?parent-page
          :where
            (page-ref ?b ?parent-page)
            [not
              (page-ref ?b ?current-page)
            ]
            [not
              (page-ref ?b "acompanhamento")
            ]
            [not
              [?b :block/marker _]
            ]
            [?b :block/content ?c]
            [not
              [(clojure.string/includes? ?c "tags::")]
            ]
        ]
        :inputs [:current-page "844746"]
        :table-view? false
        :breadcrumb-show? false
        :collapsed? true
      }

How can I get the ?parent-page without “hard-coding” it? I want to use this query as template for all my service orders.

Sorry for my english, I can provide further info if necessary.

Welcome. I’m not fully following your description, but the answer seems straightforward. If you mean:

  • the parent block ?parent of a block ?b, it is [?b :block/parent ?parent]
  • the parent page ?p of a block ?b, it is [?b :block/page ?p]
  • the namespace ?ns of a page ?p, it is [?p :block/namespace ?ns]

I think I got what I wanted

I’m on page 844746/2 and want to see all note blocks that aren’t “acompanhamento”, props and tasks from the service orders 844746/*, excluding 844746/2

  {
    :title [:h2 "testeee"]
    :query
    [
      :find (pull ?b [*])
      :in $ ?current-page
      :where
        [?p :block/name ?current-page]
        [?p :block/namespace ?ns]
        [?b :block/path-refs ?ns]
        [not
          (page-ref ?b ?current-page)
        ]
        [not
          (page-ref ?b "acompanhamento")
        ]
        [not
          [?b :block/marker _]
        ]
        [not
          [?b :block/content ?c]
          [(clojure.string/includes? ?c "tags::")]
        ]
    ]
    :inputs [:current-page]
    :table-view? false
    :breadcrumb-show? false
    :collapsed? false
    :group-by-page? false
  }

Thank you, it helped me a lot! I was a little bit confused about :block/namespace

Your query looks weird:

  • not-clauses use square brackets [not ...] instead of round parentheses (not ...)
  • checking for tags searches in :block/content instead of asking either of:
    • [?b :block/properties ?props]
    • [?b :block/tags ?tags]
    • (page-property tags ...)
    • (page-tags ...)

I may use the reference as [[Page]] instead of #tag aswell, I will fix the NOTs