HowTo? Get the values of listed fields in field & write their sum into other field

Hello @all,

In my workout-TW I have equipment for exercises, like resistance-bands. These bands I can use in different ways, which gives more or less difficulty to exercises- similar than weight of dumbbells.
So, I have the red band with several fields with the related weight (f.e.: field “red-u-2+8” with the related weight “15” and “red-u-2+7” with the related weight “17” and some more fields like this).

When I now do an exercise, I choose f.e. two resistance bands: The red one & the blue one.
Then I decide, in which weight-config I will use them and write this decision into the field “AdditionalWeight”. Then this field has the value “red-u-2+8 blue-u-1+8”.
My goal is to get the total weight I had in that exercise and to write that sum into another tiddler. >Means: Getting the related field-values (getting the related “15” of the listed field “red-u-2+8” and the same for the blue one), sum all of them and write that sum into another tiddler.

I found some snippets, but do not know, which of them would be the best and above all, how to combine everything. These snippets are:

{{{ [{!!AdditionalWeight}enlist[red-u-2+8]] :then[get[red-u-2+8]] }}}
{{{ [{!!AdditionalWeight}enlist[red-u-1+8]] :then[get[red-u-1+8]] }}}

This gets the values of the listed fields (like “15”). But I have 40 fields like this… :face_with_spiral_eyes:

The summing I could probably do with something like this {{{ [tag[log]get[run]split[ ]sum[]] }}} or this {{{ [tag[log]get[run]enlist-input:raw[]] }}}, but I don’t know how and how to adapt it to my case.

Please help…

If I understand your tiddler field usage correctly…

You have a “red band” equipment tiddler with fields:
red-u-2+8 = 15
red-u-2+7 = 17
and a “blue band” equipment tiddler with:
blue-u-1+8 = (some value you didn’t specify in your post)
and an exercise tiddler with a field:
AdditionalWeight = red-u-2+8 blue-u-1+8
which is a space-separated list of field names from various equipment tiddlers.

Assuming the exercise tiddler is the currentTiddler, you can get the individual equipment field names from the AdditionalWeight field, using this filter:

{{{ [enlist{!!AdditionalWeight}] }}}

Note: if the exercise tiddler is NOT the currentTiddler, you can use this filter:

{{{ [[SomeExerciseTiddler]get[AdditionalWeight]enlist-input[]] }}}

or perhaps something like this:

Enter exercise tiddler name: <$edit-text field=ex/>
{{{ [{!!ex}get[AdditionalWeight]enlist-input[]] }}}

Next, you want to get the related weight from each of those listed equipment fields. To do this, you can add a :map filter run, like this:

{{{ [enlist{!!AdditionalWeight}] :map[all[tiddlers]get<currentTiddler>] }}}

Note that within the :map filter run, the value of <currentTiddler> is automatically set to each of the listed “AdditionalWeight” field names (i.e., red-u-2+8 and blue-u-1+8). The all[tiddlers] filter operator tells the :map filter run to look for those field names in ANY tiddler.

The next step is to add up those retrieved related weight values, using a +[sum[]] filter run, like this:

{{{ [enlist{!!AdditionalWeight}] :map[all[tiddlers]get<currentTiddler>] +[sum[]] }}}

The final step is to provide a $button that uses $action-setfield to save the total value, like this:

<$let total={{{ [enlist{!!AdditionalWeight}] :map[all[tiddlers]get<currentTiddler>] +[sum[]] }}}>
<$button>save total<$action-setfield $tiddler="AnotherTiddler" totalweight=<<total>>/></$button>
</$let>

-e

@EricShulman Yes, you understood everything like I meant it.
And it is working like I hoped :slight_smile:
So- again a huge thankyou!
Now I am not so far away anymore from my workout-doing :smiling_face_with_sunglasses: :flexed_biceps:
Well, the last thing- the button- I did not yet test, because now I have a lot of work to do -to combine this also with other functions and then implement all this. So the button comes at last. But that is the simplest of all, so I am sure, also that one will work.