Dataviewjs getting first, second & third connections

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I want you to make a dataviewjs query for an obsidian note which does the following:
There should be three main headers printed - ‘First Connection’, ‘Second Connection’ & ‘Third Connection’.

Under the ‘First Connection’ header all the inlinks and outlinks that are connected to the current note should be listed.
Lets call this list the ‘First_Connection_list’ for explanation purpose.
Make sure that all the duplicated inlinks and outlinks that are present in the ‘First_Connection_list’ are removed. That is, all the values in this list should be unique.

Then under the ‘Second Connection’, all the inlinks and outlinks that are connected to the ‘First_Connection_list’ should be listed.
Lets call this list the ‘Second_Connection_list’ for explanation purpose.
Make sure that all the duplicated inlinks and outlinks that are present in the ‘Second_Connection_list’ are removed. That is, all the values in this list should be unique. Also, remove all the values that are present in the ‘First_Connection_list’ from the ‘Second_Connection_list’

Finally, under the ‘Third Connection’, all the inlinks and outlinks that are connected to the ‘Second_Connection_list’ should be listed.
Lets call this list the ‘Third_Connection_list’ for explanation purpose.
Make sure that all the duplicated inlinks and outlinks that are present in the ‘Third_Connection_list’ are removed. That is, all the values in this list should be unique. Also, remove all the values that are present in the ‘First_Connection_list’ & ‘Second_Connection_list’ from the ‘Third_Connection_list’

Things I have tried

// Define a function to get the unique inlinks and outlinks of a given note
function getConnections(note) {
    let inlinks = dv.links(note).incoming;
    let outlinks = dv.links(note).outgoing;
    // Merge and deduplicate links
    let allLinks = [...new Set([...inlinks, ...outlinks])];
    return allLinks;
}

// Get the unique inlinks and outlinks of the current note
let firstConnectionList = getConnections(dv.current());

// Print the 'First Connection' header
dv.header(1, 'First Connection');

// Print the links under the 'First Connection' header
for (let link of firstConnectionList) {
    dv.paragraph(link.path);
}

Trying to do something like this.
<!-- Below this line, write what terms you searched in the help docs and forum, plus any solutions you tried and what happened. -->

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