Automatic Alias if title+prototype already exists

Pat: I am intrigued. I’ll take a look at your link, thank you!

Mark, what a wonderful tour of action code and export codes. It is a model of clarity and a very generous contribution to the community. Thank you. David.

I hope @mwra will allow me to take this one step further, as I have been unsuccessful in modifying the above to slightly different needs.

I have a prototype for “Keywords”. For each note using this prototype, I want the note’s text to equal a list of the $Name and $ID of all other notes in which the name of this note exists a ‘set’ attribute (like $Keywords) of those notes.

For example, I have a note named ‘banana’. The text of this note should list the name and ID of all notes in which “banana” is a term found in their $Keywords attribute.

The code provided in the thread above produces a single note listing all the keywords in the document, and, under each keyword, the name of all notes in which they occur. What I’d like is just a list of those notes in which the name of the present note occurs as a keyword.

Thus far, I’ve managed:

$MySet=$Name(find($Keywords.icontains($Name(current))));
$Text=format($MySet,"\n");

But I haven’t been able to figure out how to get both the $Name and $ID for each such note. Any help would be appreciated.

Can’t actually test code [sic] right now but…

I’ll assume $MySet is returning the right matches. We’ll change the code slightly so $MySet gets a list of $paths for those notes. Now:

$MyList=;
$MySet=find($Keywords.icontains($Name(that))&$IsAlias==false);
$MySet.sort.each(aValue){
   $MyList = $MyList + ($Name(aValue) + " " + $ID(aValue));
}
$MySet=;

So, first we reset $MyList for the current note as we want a fresh listing. Then, we collect all the $Path values where the current note’s $Name is a $Keyword value in that note. As find() doesn’t de-dupe like a query, the $IsAlias test ensures we only match original notes.

Next, we sort the set and iterate using .each(). Each aValue is actually the path to a note so we collect the $Name and $ID of the note at that path, joined with a space (you might want to edit that separator to something else). We put parentheses around that task so it is a single literal string by the time we add it to $MyList where it becomes a new value.

Sorry I can’t test code just now but i hope that works. Note the use the need to use the that designator in the query so we use the value of the note calling the find(). current is testing the note currently being tested by the find() - so will return everything as every note will match itself!

OK, I ran the above as an edict in your file keyword-test2edV2.tbx. I added a note called ‘banana’, ran the edict, and $MyList now shows:

note4 1553467228;note5 1553497378

So, I think it works.

I can confirm it does. And I’ve learnt a bit more about the code needed to do it. Thank you again, Mark.

1 Like