Ancestors FIlter question

HI ,

I have a number of tiddlers in a hierarchy , they reference each other in Field1

So tiddler 1 has in field1 the values 2.1, and 2.2 and so forth

I am trying to use the Ancestors filter to do the following

1.for every tiddler go through its hierarchy 1 level up using the reference in field1 , get the contents of the parents text field , then go back to update field1 value with the result

so i want tiddler 1 to go lookup tiddler 2.1, and 2.2 text field value , then go back and overwrite the value of field1 in tiddler 1 with the result

i am using numbers for the tiddler names to help illustrate the hierarchy

  • 1
    • 2.1
    • 2.2
      • 3.1
      • 3.2

I am using the below code, which works, except when it comes to a fork , it only updates field1 with one of the results( i believe its prob the first result)

<$button>update fields
<$list filter = "[has[field1]]">
<$list filter="[<currentTiddler>ancestors[field1],[1]!title<currentTiddler>get[text]]" variable="gettext">
 <$action-setfield  field1 =<<gettext >>/>

the example is in https://mighty-soap-71.tiddlyhost.com/

My question is , how do i get this code to update field 1 with multiple values if the tiddler has multiple parents or siblings(depends on how you see it ) .

also how can i add brackets to the results , so if i have 1 or to results, how can i have them both updated in field1 wrapped in double brackets [[]]

thank you for reading all this , and hope it makes sense

Hi,
this is not really a question related to the ancestors filter, but this might help anyway:
If you change the filter

...get[text]]

to

...get[text]format:titlelist[]]

you should get exactly what you need.
See also https://tiddlywiki.com/#format Operator.

Yaisog

Thanks Yaisog,and yes i agree the title is misleading sorry about that ,

i didnt know the format operator can do that , ok this is great this solves the brackets problem,

however i am still having the main problem with only one value from the evaluated result being updated in field1 , i have changed that to field 2

as you can see below ,the the filter is evaluating 2 values, yet the action widget is only updating one

btw this question is not necessarily directed to you , but to any one can help me with this

thanks again

Ah, sorry, forgot that part.

...get[text]format:titlelist[]join[ ]]

should get you there.
When assigning a list to a parameter, only the first item of the list will be assigned. Using join[] you just glue together all items (using a space as separator), so they can be assigned as essentially a single item.

Yaisog

Looking at your button code, it seems you’re calling the action within the list filter (and the list can thus only have one value assigned to <<gettext>> at the time when the button-action is triggered).

I think you can ditch the variable within your list filter, and just set the field directly this way:

<$action-setfield field2={{{ [<currentTiddler>ancestors[field1],[1]!title<currentTiddler>get[text]format:titlelist[]join[]] }}}/>

(I hope I’ve typed it right, based on your screen image. You get the idea, though, yes?

@Yaisog @Springer both solution work ,and new things i did not know , thank you for helping out :slight_smile:

1 Like