Any simple way of delaying an action?

I am sure this is trivial problem. But, I cannot fiture it out.

The second action runs based on the product of the first. But, I don’t want the second to run immediately.

Action1: if($StartDate==date(“never”)) {$StartDate=date(“today”)};
Action 2: if($EndDate==date(“never”)) {$EndDate==($StartDate + 15 days)};

I don’t want Action2 to apply as soon as I assigned the Protype. I want to run may after 20 minutes so that it gives me to fix the value of $StartDate. Once I fixed the $StartDate, the $EndDate calculates the values from the value I manually fixed for the $StartDate.

Further to the above…

first, a quick syntax note. As written, your ‘action’ won’t work as expected. ‘==’ is an ‘is equal to’ test giving a true/false answer and intended for use in queries, i.e. the if(query){} part of your conditional statement. A single ‘=’ means apply this value (right side to left side) and should not be used for queries.

Here is a solution to the original question above, though I commend the comments in the answer above:

if($StartDate==date("never")) {
   $StartDate=date("today")
};
if($StartDate & !$EndDate & (minutes($StartDate,date("now"))>20)){
   if($EndDate==date("never")) {
      $EndDate=date($StartDate + "15 days");
   };
};

Basically, apart from a syntax fix to action #2, I have added a further enclosing condition with a 3-part query. First we check notes have a $StartDate (we only act on those) and then also check that the $EndDate is not set as we don’t want to re-set existing end-dates (if you do want the latter omit this clause). Lastly, having matched the notes we think need action, we check the $StartDate is at least 20 minutes ago.

1 Like

Thank you for explaining the difference between the two equals @mwra. I have always confused these two.

And, for the complex syntax. wow…

The core of the extra query is a simple minutes() calculation. The other terms are there to filter out effects you don’t want. As a general design point it’s best to run actions on as few notes as possible. this is (a) good for overall efficiency performance—at lest in bigger TBXs—and (b) so you don’t mistakenly re-alter notes you didn’t mean to.

I’d run this code as a stamp or an edict

1 Like

is the 20 minute a waiting (delay) time for the second action to apply?
It seems to apply immediately.

Sorry, it is not applying immediately. that is my fault. It is working fine. thanks

1 Like

2 posts were split to a new topic: Problem with backreferences