Thanks a lot Eric Shulman. I was missing the "enlist" and "get" functions.

Based on reading one of the other thread, I realized that Button is the 
only one that can trigger the action-setfield. Is there a plan in the 
future where I could change the "sequence" in one Tiddler and all the 
tiddlers that depend on it recompute its own "sequence" value automatically?

Also, thanks for showing me how to do templates. I can see its benefits and 
I'm refactoring my wiki to use templates now

Thanks,
Bhilhanan Jeyaram

On Tuesday, 3 November 2020 at 14:29:27 UTC-8 Eric Shulman wrote:

> On Tuesday, November 3, 2020 at 1:54:31 PM UTC-8, Bhilhanan Jeyaram wrote:
>>
>> A tiddler "Tiddler 2" has a field "depends-on" with value "[[Tiddler 1]] 
>> [[Tiddler 3]]". Each each these two tiddlers has a field "sequence". Let's 
>> say "Tiddler 1":sequence=1 and "Tiddler 3":sequence=2. I'm trying to parse 
>> the list of "depends-on" and get the max value of "sequence" and then 
>> increment that number by 1 and assign that value to "Tiddler 2". In this 
>> example "Tiddler 2" will have the "sequence" value assigned as 3
>>
>
> You will need to use a $button widget to modify a tiddler and set a field 
> value.
>
> Place the following into Tiddler 2:
>
> <$button> set sequence
>    <$action-setfield sequence={{{ 
> [enlist{!!depends-on}get[sequence]nsort[]last[]add[1]] }}} />
> </$button>
>
> Notes:
> * enlist{!!depends-on} gets the list of tiddlers that the current tiddler 
> depends on
> * get[sequence] gets the sequence field value from each of those tiddlers
> * nsort[] does an ascending numeric sort of the sequence numbers
> * last[] gets the last number (i.e., the max value)
> * add[1] increments that number
> * the result of the entire filter (the new number) is then assigned to the 
> sequence field of the current tiddler
>
> Note: you can put the above button into a separate tiddler (e.g., 
> "SetSequenceNumber") and then transclude it using:
> {{||SetSequenceNumber}}
>
> Alternatively, you could tag the SetSequenceNumber tiddler with 
> $:/tags/Macro, containing:
> \define SetSequenceNumber()
> <$button> set sequence
>    <$action-setfield sequence={{{ [enlist{!!depends-on}get[sequence]nsort
> []last[]add[1]] }}} />
> </$button>
> \end
> Then, to invoke the macro, you would add the following in "Tiddler 2"
> <<SetSequenceNumber>>
>
> enjoy,
> -e
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/733dca4b-f7d4-4d9a-90bf-dec0ba675f51n%40googlegroups.com.

Reply via email to