Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Checking code upgrade
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1433545246

Message started by Stephen Hay on Jun 5th, 2015, 7:00pm

Title: Checking code upgrade
Post by Stephen Hay on Jun 5th, 2015, 7:00pm

Hello again,

This is code that worked fine in Tbx 5 and seems to work okay in TB6.

if($CriticalFew="true"){$NextContact=$LastContact+"7weeks"} else {$NextContact=$LastContact+"3months"};$StartDate=$LastContact

The $StartDate part is so I can use Timeline to see my network over time.

Is it still correct, though?

Thanks,
Stephen

Title: Re: Checking code upgrade
Post by Mark Anderson on Jun 6th, 2015, 4:29am

The if condition only works because of legacy syntax support. In an if() query, use == to test equality of 2 things.  Also, boolean true values are lowercase true/false and not quoted.

A better syntax for the date maths is $SomeDate = date($AnotherDate + "4 weeks") - see more.

if($CriticalFew==true){$NextContact=date($LastContact+"7weeks")} else {$NextContact=date($LastContact+"3months")};$StartDate=$LastContact

This is the above, just laid out in easier-to-read form for later readers:

if($CriticalFew==true){
   $NextContact=date($LastContact+"7weeks")
} else {
   $NextContact=date($LastContact+"3months")
};
$StartDate=$LastContact


Note that a single - or the last - expression in {} sections don't need a semi-colon terminator, nor does the last expression. But we do need a semi-colon after the lat } of the if clause as it is the end of that expression and a separate expression follows (@Stephen got all that part right lest I imply otherwise).

Title: Re: Checking code upgrade
Post by Stephen Hay on Jun 6th, 2015, 7:00pm

Thanks, Mark but credit where credit is due. Given my coding abilities, it is most likely that you provided me with the v5 code in the first place...

Title: Re: Checking code upgrade
Post by Mark Anderson on Jun 6th, 2015, 7:46pm

No worries. In trying to suggest 'best practice' it's all too easy to appear pedantic. Web pages live a long time and there are plenty of old code examples around for an app that's now 15 years old.  :)

For later reader, I'd comment the tutorials/walkthroughs (written by Mark B) in the app's Help menu. For my own efforts, I've tried to weed legacy code from the v6 aTbRef.  I'm not totally done revising and am very happy to hear of pages that are ambiguous in this regard; there are >3.5k sourece notes so it's hard to re-read everything regularly.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.