Cannot use a variable from a filter. Can someone help me ?

275 views
Skip to first unread message

vpl

unread,
Aug 22, 2021, 4:24:58 PM8/22/21
to TiddlyWiki
Hi,

I'm trying to run the following code (at the end of the message) which uses a variable called 'target' (that contains the current date) into a filter called todayfilter

When I set the  todayfilter 
<$vars todayfilter="[get[task_date]compare:string:eg[2021-08-22]]">
All works fine (I mean the list <$list filter="[regexp[db___]!sort[task_start_time]filter<todayfilter>]"> 

When I set the  todayfilter using the <target> variable (as in the code below) this does not works. I've tested several syntax options without success ...

Any expert to tell me when the syntax is wrong ?
Many thanks , Regards
Vpl

\define now_val()
<$vars now_date=<<now YYYY-0MM-0DD>>>
<$vars  target={{{ [<now_date>] }}}>
<<target>>

<$vars todayfilter="[get[task_date]compare:string:eg[<target>]]">

<table><tbody>
<tr><th>Date</th><th>Project</th><th>Task</th><th>Start</th><th>Stop</th></tr>
<tr>
  <td>&nbsp;</td>
  <td align="right">//Number of tiddlers//</td>
  <td colspan="4">''<$count filter="[regexp[db___]filter<todayfilter>]"/>''</td>
 </tr>
<$list filter="[regexp[db___]!sort[task_start_time]filter<todayfilter>]">
<tr>
<td><$link><$view field="task_date"/></$link></td>
<td><$view field="tags"/></td>
<td><$view field="task_comment"/></td>
<td><$view field="task_start_time"/></td>
<td><$view field="task_end_time"/></td>
</tr>
</$list>
</tbody></table>

\end

<<now_val>>

TW Tones

unread,
Aug 22, 2021, 6:16:26 PM8/22/21
to TiddlyWiki
I just had a quick look at your code

<$vars todayfilter="[get[task_date]compare:string:eg[<target>]]

Try;
vars todayfilter="[all[current]get[task_date]compare:string:eg<target>]"

Tones

vpl

unread,
Aug 23, 2021, 4:55:22 AM8/23/21
to TiddlyWiki
Hi Tones
Thanks very much for this answer
I've tested your option and get a TiddlyError Cannot read property getVariable of undefined ... I've attached the screenshot for référence
To ease the analysis I've attached the tiddywiki. When you open it you arrive to the CurrentDay tiddler which contains the code
I've commented the option you proposed as it triggers this error

Thanks very much for your help and support

Regards

Vpl

bug-filter.png
Time-tracker-support.html

Eric Shulman

unread,
Aug 23, 2021, 7:45:27 AM8/23/21
to TiddlyWiki
On Sunday, August 22, 2021 at 1:24:58 PM UTC-7 vpl wrote:
I'm trying to run the following code (at the end of the message) which uses a variable called 'target' (that contains the current date) into a filter called todayfilter
\define now_val()
<$vars now_date=<<now YYYY-0MM-0DD>>>
<$vars  target={{{ [<now_date>] }}}>
<<target>>
<$vars todayfilter="[get[task_date]compare:string:eg[<target>]]">

Replace the first four lines of the macro with these three lines:
<$vars target=<<now YYYY-0MM-0DD>>>
<<target>>
<$vars todayfilter="[<currentTiddler>get[task_date]match<target>]">

Notes:
1) Assign the date to the target variable in one step.  There's no need for "now_date".
2) The filter needs <currentTiddler> preceding get[task_date], otherwise it will get the task_date value from every tiddler that has that field!
3) The compare "mode" should be "eq" (abbreviation of "equal") not "eg".
4) For a simple string comparison, you can use the "match" filter operator.

Let me know how it goes,

enjoy,
-e

vpl

unread,
Aug 23, 2021, 8:13:22 AM8/23/21
to TiddlyWiki
Hi,
Thanks a lot; I agree for 1), 3) and 4)

But for point 2) in fact what I need to do is the following code 
<$vars now_date=<<now YYYY-0MM-0DD>>>
<<target>>
<$vars todayfilter="[get[task_date]match<target>]">
<$list filter="[regexp[db___]!sort[task_start_time]filter<todayfilter>]">
<tr>
<td><$link><$view field="task_date"/></$link></td>
<td><$view field="tags"/></td>
<td><$view field="task_comment"/></td>
<td><$view field="task_start_time"/></td>
<td><$view field="task_end_time"/></td>
</tr>
</$list>
</tbody></table>

I use the filter operator into the list as I want to filter the tiddlers based on the task_date  field
For each of the filtered tiddlers I display the fields in the table
If I put the "get[task_date]" directly into my final filter  like that (<$list filter="[regexp[db___]!sort[task_start_time] [get[task_date]match<target> ">) I do not have the tiddler fields to display

More, When I try the below code I get a Tiddler exception (attached in my previous post ...)

Is there a bug in the filter operator or something wrong I'm doing ?

Regards

Eric Shulman

unread,
Aug 23, 2021, 8:25:36 AM8/23/21
to TiddlyWiki
On Monday, August 23, 2021 at 5:13:22 AM UTC-7 vpl wrote:
Thanks a lot; I agree for 1), 3) and 4)
But for point 2) in fact what I need to do is the following code 
<$vars now_date=<<now YYYY-0MM-0DD>>>
<<target>>
<$vars todayfilter="[get[task_date]match<target>]">
I use the filter operator into the list as I want to filter the tiddlers based on the task_date  field
For each of the filtered tiddlers I display the fields in the table

Ah, yes...I see now.  You do want to find all tiddlers that have a "task_date" field, not just check the current tiddler.

More, When I try the below code I get a Tiddler exception (attached in my previous post ...)
Is there a bug in the filter operator or something wrong I'm doing ?

I think you missed a change on line 1.  Instead of:
<$vars now_date=<<now YYYY-0MM-0DD>>>
you want:
<$vars target=<<now YYYY-0MM-0DD>>> 

-e

vpl

unread,
Aug 23, 2021, 8:37:20 AM8/23/21
to TiddlyWiki
You are obviously right ... thanks
But even with that I still get an Tiddly exception
FOr your convenience I've prepared a small tiddly with the code (tiddler test) as an attachment

Open the test tiddler and replace the 
<$vars todayfilter="[get[task_date]match[2021-08-23]]">
by
<$vars todayfilter="[get[task_date]match<target>]">

You will get a javascript exception as I mentioned in the previous posts of this conversation

Is it a bug ?

Thanks for your help

Regards
debug_pb.html

Jean-Pierre Rivière

unread,
Sep 24, 2021, 5:23:23 AM9/24/21
to TiddlyWiki
Yes it does trigger a javascript exception.

The following code does the things you want, if I have well understood your goal.

<$vars target="<<now YYYY-0MM-0DD>>">
<$wikify name=todayfilter text="
 [get[task_date]match[<<target>>]]">
<<target>> : <<todayfilter>>

<table><tbody>

<$list filter="[regexp[db___]!sort[task_start_time]filter<todayfilter>]">
<tr>
<td><$link><$view field="task_date"/></$link></td>
<td><$view field="tags"/></td>
<td><$view field="task_comment"/></td>
<td><$view field="task_start_time"/></td>
<td><$view field="task_end_time"/></td>
</tr>
</$list>
</tbody></table>
</$wikify></$vars>

Reply all
Reply to author
Forward
0 new messages