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


(Desalegn) #1

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?


(Mark Anderson) #2

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).


(Mark Anderson) #3

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.


(Desalegn) #4

Thank you.
This worked perfectly.

What does -1 stand for?


(Mark Anderson) #5

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


(Pat Maddox) #6

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)