Any way to remove the $Path from the $Find query

I was trying to assign a value to an attribute by searching inside the attribute of another note.

if($Father==""){$Father = (find ($Prototype=="Male"&$Begot.contains($GivenName(that))))};

This is assigning the name and path like Geo/John as a value for $Father attribute. I want only the name (removing the $Path) value.

How can I remove the path?

As you’ve found find() returns $Path which is a/` delimited path of note names. So:

if($Father==""){
   $MyString=find($Prototype=="Male"&$Begot.contains($GivenName(that)));
   $Father = $MyString.split("/").at(-1);
   $MyString=;
};

I’m using $MyString as when I tried using a var $Father was the var name. Anyway, the above works for me.

Edit: Tinderbox seems to cope but there shouldn’t really be a space between find and the parentheses holding its inputs).

got it. this is cleaner if you don’t want to use an attribute as an in-loop value holder:

if($Father==""){
   var X;
   X=find($Prototype=="Male"&$Begot.contains($GivenName(that)));
   $Father = X.split("/").at(-1);
};

Tested in b318.

1 Like

Thank you.
This worked perfectly.

What does -1 stand for?

The last item in a list. See here for more.

1 Like

Perhaps collect_if would come in useful here? It collects attributes from notes matching your query. It seems like you’re trying to get $Name here, so you might try to get that directly:

$Father = collect_if(all, $Prototype=="Male" & $Begot.contains($GivenName(that)), $Name)

(I haven’t tested it, so it’s possible that the that designator isn’t correct for collect_if)

1 Like