Which value(s) for $EndDate?

What am I doing wrongly?

if($Checked=true){$Badge=Check mark; $EndDate=now} else {$Badge=clock; $EndDate=never};

Using values such as “now/today/current” always results in $EndDate being updated every minute; which, of course, I don’t want. I just need to log the $EndDate and then have it remain unaltered.

Ideas?
Cheers!

Um , that code looks wrong. Strings are quoted (and built-in badge names are lowercase):

if($Checked==true){$Badge="check mark"; $EndDate=date("now")} else {$Badge="clock"; $EndDate=;);

2 Likes

well, @mwra, the code you kindly provided does not do the trick as far preventing $EndDate from being update every minute is concerned.

And, surprisingly, badge names work, too, if not lowercase and they don’t seem to need “quotation marks” either. Strange? Or just forgiving - codewise?

The latter, or in relation to quotes. The badges is interesting as I previously understood them to be case-sensitive. I suspect they are but if no match Tinderbox probably silently tries a case-insensitive match.

I didn’t have a chance to build a test for your code last night so my post was just testing for a code syntax error.

I think the functional error is your ‘if’ test. I suspect you want to only set the current time if $EndDate_ is not already set_. If so, your test should be:

if($Checked==true & $EndDate!="never")...

That way, checked notes with an EndDate aren’t reset.

In addition to @mwra’s always-authoritative advice, there’s another trick, just in case you (@andreas) are not aware of it or have forgotten about it. It’s the |= operator, the “pipe” symbol followed by the equal sign.

If the action part of your agent says the following:

$EndDate|=date("now")

Then the value for $EndDate will be updated only if it hasn’t already been assigned a value. Otherwise the value remains what is already there. It’s a different way of testing for an empty / default-value / unassigned field (recognizing slight differences among these).

The way I think of the |= operator, which I use all the time, is that it assigns a value where there isn’t one, but it doesn’t mess up any value you have intentionally assigned. aTbRef has the more detailed explanation here.

4 Likes

it does work just as you said, @JFallows, and just as I need it to. Thanks you!

Hi guys,

I tried to copy this approach and created a rule of my Task prototype:

if($ChildCount>0){$Prototype="Project"}; if($Checked==true & $EndDate!==never){$Badge="check mark"; $EndDate=date("now")} else {$Badge="calendar"; $EndDate=;); 

The checkmark badge appears when clicking the tick box in checked and the date stamp is now when never was an attribute.

However, the EndDate was still overwritten if it contained a value. Also, when unchecking the box, the checkmark remained… if it could also revert the EndDate to never things would be even better…

Any pointers?

Cheers,

J.

Looing at the code in the rule Inspector we see a syntax error auto-detected, though it shouldn’t matter:

Let’s add some white space (which doesn’t affect the rule) to get clarity and fix any closure errors:

So, the code:

if($ChildCount>0){
   $Prototype="Project";
};
if($Checked==true & $EndDate!==never){
   $Badge="check mark";
   $EndDate=date("now");
}else{
   $Badge="calendar";
   $EndDate=;
};

By !== I assume you want to test 'not equals ’ in which case you need a !=, i.e. $EndDate!="never"

Now the problem is that on pas #1 for a checked item with no end date, the $Badge and and $EndDate
are set. On pass #2 the same note now has an $EndDate so goes straight to the end branch resetting the $EndDate so nothing appears to happen.

Try writing out the logic in English (or first language). Recall that the an if() condition’s action is not undo when the condition is no longer met, unless you add further code to do so. Plus when the if() condition’s query has two terms and an AND (&) join the condition is only met if both conditions are true.

So, I’m sure this is fixable but your intent is not fully clear from the above.

Thanks Mark,

extremely helpful. I want to achieve that a task that has previously been marked as completed and which needs to be reactivated can be reactivated by unticking the checked box. As a consequence I would like changes to the badge and the end-date.

I hope this clarifies things.

Thanks for taking the time!

Try this rule:

if($ChildCount>0){
   $Prototype="Project";
};
if($Checked==true){
   // checked so set a badge
   $Badge="check mark";
   // if no end date, set now, as task done
  // (else no need as end date already set)
   if($EndDate!="never"){
      $EndDate=date("now");
   };
}else{
   // task remains incomplete 
   // or reset as incomplete
   $Badge="calendar";
   // clear end date if previously set
   $EndDate=;
};

Comments and whitespace/line-breaks are for clarity. You can remove them if you wish. In the else we don’t need to test - we want the default/empty date and this needs no extra calculation, so do to all in this branch.

An unhandled aspect is whether $EndDate or $Badge need to alter if the note becomes a project (by gaining children.

Thanks Mark,

Will try that as soon as I am back at the desk!
The aspect of the task becoming a project by gaining children is a very valid concern! Additionally, I am planning to read up on using the date fields to maybe have an agent/ideally some other process use the information to maybe move aliases of the notes highlighted in bold read on the route screen as a reminder… This is probably easier than it seems, but at the moment still daunting. Unfortunately, I might be dropping only promise me to Double every so often despite me immensely enjoying the journey!

Again, thank you so much for your patience and input! Cheers, Doc C

No worries, the whole point of the community is its here.

That sort of UI-only criteria may make life hard. Bolded titles might be hard to spot. Better is to learn to set some metadata (an easily queried attribute value) as the primary maker and thus the latter as trigger for UI styling like bolding titles.

Is a bolded title an attribute value/ Yes, but experience tells me a visual-first primary marker wants to be used with card. Bolded titles aren’t always clearly that. The issue is less setting the attribute but us the user ‘reading’ the Ui and setting the metadata accordingly. I’ve learned the hard way that the UI is better visualising the ‘real’ data I’m using for analytical heavy lift rather than the other way around. Others may take a different view. :slight_smile:

Hi Mark,

check/uncheck works. I changed the if($EndDate!="never"){ $EndDate=date("now") to $EndDate==“never” then it runs as intended! Thank you so much!

To clarify my second intention, I basically would like overdue tasks (that don’t have a completed checkmark) to pop up in the root level screen, preferably in some color coding of the note itself, that disappears when task is “checked” as completed.

will dig into that… is that better done by adornments/agents/something entirely different?

cheers,

doc c

$DueDate.day<7 & $DueDate!="never" & $Checked==false;

is what I tried as agent query. this collects them AFAIK and could demonstrate when running trials. However, still looking to make them more visible on the root screen instead of looking inside the agent…

any pointers?

cheers,

Doc_C

How about using a summary table on the agent? Then you could see the notes found — or at least some of the notes found — as a list.

A common shortcut is to use a $DisplayExpression on an agent that shows how many items need your attention:

 $Name+" ("+$ChildCount+")"

This can be handy for things like “Overdue Tasks (3)”

Cool Idea!. Where do I put the code?

Originally, I was hoping for something that just dumps the aliases in plain view like a dashboard type thing. But if that is hard/not feasible, I like the counter idea…

Cheers,

Doc C.

Found where to put the code…

Quick update, I have created an adornment to fetch all tasks that have a “true” statement for the UserAttribute “Urgent”. This, to my surprise due to complete ignorance, pulled the notes onto the adornment and just kicked them off to the side when “unchecking” “urgent”. Also, color coding actions where not reversed either.

Onto creating an agent, I managed to pull all urgent notes and make the change colors. Unfortunately, the color was also applied to the original note and not only the alias. This, was also not reversed when unchecking the “urgent” attribute.

For now, the agent solution without color coding will probably suffice but I do appreciate input to improve matters.

All the best and thanks for all the help,

Doc_C

The color of an alias is the color of the original. Aliases share all the properties of the original, aside from a very small collection of intrinsic attributes which can’t be shared — things like $Xpos and $Width.

Time to check your assumptions. Where does it say this will happen? Or are you mistaking intent—i.e. you want colours to toggle—in some context. Which begs the question, toggle to what? As you add more conditional code, “whatever it was before” starts to become less easily guessed.

Generally, if setting something like $Color with a conditional to give a visual tell-back of state, you should define both states using both condition branches if(){...}else{...}. In this scenario, the else branch is where you reset things.

If values set by conditional action code don’t change (back) as expected, look at your query in the if(query). Ask yourself why is the this note not reaching the else branch. Thinks to look out for:

  • With multiple argument queries doesn’t just consider the first item but the whole query
  • With nested if() statements, the test note might hit the else branch in a nested query but never gets to be evaluated in that context because it fails to hit the right branch in the outer query. Code can be frustrating in showing how the human brain elides detail we consider obvious or unneeded. By comparison the code work on the data it has within the fixed logic we code so does what we say but not necessarily what we imagined happening.

See more: