Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Agent's Display Expression counts children (Read 1428 times)
John Doernberg
Full Member
*
Offline



Posts: 37

Agent's Display Expression counts children
Sep 12th, 2016, 2:02pm
 
I have a TBX file from a couple of years ago in which (with Mark's copious help) one of my agents has a DisplayExpression that counts the number of items retrieved by the agent using their respective prototypes.  It's very helpful, but when I copied and pasted it into a different file and changed the prototype names to reflect the new file, it returned "0" items for each prototype except one. I can't figure out why, although it strikes me as possible that this is a legacy syntax that has been deprecated. For what it's worth, the agent is intended to retrieve the number of items that fell within the selected month based on their $KeyDates (a user attribute). Here is the Display Expression:

$Name+": "+$ChildCount+" entries"+" ("+count(collect_if(children,$Prototype=“p_Task”,$Name))+" Tasks, "+count(collect_if(children,$Prototype="p_Event",$Name))+" Events, "+count(collect_if(children,$Prototype="p_Book",$Name))+" Books, "+count(collect_if(children,$Prototype=“p_Note”,$Name))+" Notes, "+count(collect_if(children,$Prototype=“p_Idea”,$Name))+" Ideas"+")"

The only item it returns properly is the number of Events. What am I doing wrong? Thanks for your help.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Agent's Display Expression counts children
Reply #1 - Sep 12th, 2016, 3:17pm
 
First, have you checked the agent contains items of the other prototypes that should be found by the agent?
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Agent's Display Expression counts children
Reply #2 - Sep 12th, 2016, 3:38pm
 
Looking at your code you've got some curly quotes in there (e.g. around prototype Task, Note and Idea). That might just be typo in transcription but, action code must use only straight quotes (pairs of single or double) to enclose strings.

count(collect()), etc., can now be written collect().count but the latter does the same thing. However it does remove one set of parentheses.

Legacy code alert. Don't use '=' for 'is equals to' test, use '=='. A single = should only be used for assignment:

Set $Color to blue:  $Color = "blue"
Test $Color is blue:  $Color == "blue"

One equals used to do both and TB guessed intent. It still does but action code's more complex and you're better using the correct operator for the desired task.  See aTbREf for more on codes.

So (line breaks are just so it fits on screen better here) here is the DE code with the quotes fixed, using .count and == for comparisons:

$Name+": "+$ChildCount+" entries"+" ("+
collect_if(children,$Prototype=="p_Task",$Name).count+
" Tasks, "+
collect_if(children,$Prototype=="p_Event",$Name).count+
" Events, "+
collect_if(children,$Prototype=="p_Book",$Name).count+
" Books, "+
collect_if(children,$Prototype=="p_Note",$Name).count+
" Notes, "+
collect_if(children,$Prototype=="p_Idea",$Name).count+
" Ideas"+")"


Better would be to use a rule to set $MyString to the output of the above and then make the DE code just $MyString.

Rule:
$MyString = $Name+": "+$ChildCount+" entries"+" ("+
collect_if(children,$Prototype=="p_Task",$Name).count+
" Tasks, "+
collect_if(children,$Prototype=="p_Event",$Name).count+
" Events, "+
collect_if(children,$Prototype=="p_Book",$Name).count+
" Books, "+
collect_if(children,$Prototype=="p_Note",$Name).count+
" Notes, "+
collect_if(children,$Prototype=="p_Idea",$Name).count+
" Ideas"+")"


DisplayExpression:
$MyString

This makes all the calculation happen. The DE simply shows the current (static) $MyString value as updated via the rule. In general you don't want a lot of calculation in a DE as it can slow things up a bit.
Back to top
 
« Last Edit: Sep 12th, 2016, 3:39pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
John Doernberg
Full Member
*
Offline



Posts: 37

Re: Agent's Display Expression counts children
Reply #3 - Sep 12th, 2016, 4:26pm
 
Thank you. I copied and pasted your code, changing $MyString to an attribute that I put into DisplayExpression instead of the code I had there (by the way, the apparent brackets are straight parenthesis in my version, so I think that is just how they appear). Funny result. The agent in question happens to contain only Events and Tasks. With my old version, it properly returned the number of Events but 0 Tasks even though there were some. After I used your version, it returns the proper number of Tasks but 0 Events.
Back to top
 
« Last Edit: Sep 12th, 2016, 4:28pm by John Doernberg »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Agent's Display Expression counts children
Reply #4 - Sep 12th, 2016, 4:40pm
 
At this point, with such code I test each collect_if() on it's own. IOW, I'd either make 4 more string attributes or set $MyString in turn to each count. Thus first check is:

$MyString = collect_if(children,$Prototype=="p_Task",$Name).count;

If the count is OK, change the prototype and check the next one, etc. This will tell you if the failure is in the individual collect statements or in your overall concatenation string.

I thought the quotes might be OK at source, but better safe than sorry! No censure intended.

The == test is cases sensitive so check the test strings are the same case as the actual prototype names.

If you can link to a small test file that shows the problem it might be easier to diagnose but otherwise we can carry on here.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
John Doernberg
Full Member
*
Offline



Posts: 37

Re: Agent's Display Expression counts children
Reply #5 - Sep 12th, 2016, 6:37pm
 
Thanks, I'll work that out in a test file created from a duplicate of the original. It's a pretty safe assumption with me that through trial and error I have larded my file with a lot of detritus over time that didn't manifest itself when entered but eventually causes problems.
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print