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
Exporting a simple list... (Read 10317 times)
AGHorne
Full Member
*
Offline



Posts: 116

Exporting a simple list...
Nov 18th, 2010, 11:57pm
 
I'm not very savvy when it comes to TB exports. I have an inventory list of items and I've made two user attributes called "Quantity" and "ApproxValue".
I would like to export this list, in text, with the title, quantity, and approxvalue.

I'm using the code:
^get(Name), ^get(Quantity), ^get(ApproxValue)

and it's not creating a list.  Any help would be great!  

Also, how would I, if possible, collect the entire value of the list.  I'm having trouble plugging in the sum code...

Back to top
 
« Last Edit: Nov 18th, 2010, 11:58pm by AGHorne »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Exporting a simple list...
Reply #1 - Nov 19th, 2010, 5:37am
 
Assumptions:
- we're exporting to text.
- we're exporting the container holding all the items as direct children OR an agent finding all items

Although we're exporting to text, we still use the HTML export mechanism - just with slightly different templates. We'll use the envelope/letter technique where a container uses an 'envelope' template which in turn includes each child's data using a second 'letter' templates; by this metaphor, a container with 3 children will be a 3-sheet letter.

I've used £ for a currency symbol - change it to whatever you use or simply delete altogether. It is used 2 twice in the Page template (column title and in totals) and once in Item (value of $ApproxValue)

Make 2 export template notes. A good Idea is to first add the built-in prototype "HTML Templates (see File menu, Built-in Prototypes sub-menu) and use that as the prototype for your template note.

The first template is called 'Page'. Here is the code:
Code:
Items

Name	Quantity	Approximate Value (£)

^children(Item)^

Total Items: ^value($ChildCount)^
Total Number of pieces: ^value(sum(children,$Quantity))^
Total Value: £^value(format(sum(children,($Quantity * $ApproxValue)),2))^ 


In the code above, the column titles have a tab between each item.

The second template is called 'Item':
Code:
^value($Name)^	^value($Quantity)^	£^value(format($ApproxValue,2))^
 


Again, the column values have a tab between them. Do make sure the line of code has a return at the end so the next item exports on a new line.

The reason format() is use with the currency is we want values like £12.50 not £12.5. So format($NumAttr,2) ensures there are always 2 decimal places which are zeroes if there is no actual value, thus 50 -> 50.00, 12.5 -> 12.50. There isn't a simple way, IIRC of inserting commas or other locale specific currency formatting, e.g. as in £5,000 instead of £5000. Mark B will doubtless correct me if my memory errs here.

Now, select your container or agent and open it's HTML view. From the template selector, chose your 'Page' template and you should see your list all ready for export.  If OK, click the Export button top right of the view and you're done  Format not quite right? Simply adjust the templates and open the HTML view again (or click the 'Update HTML' if the view is still open).

With tabular output as here don't expect TB to add extra tabs between columns where value lengths vary - you'll need to tidy that after export in your text editor.

A quick demo is here (right click link and choose "download linked file as..." option).

I hope that helps.
Back to top
 
« Last Edit: Nov 19th, 2010, 5:40am by Mark Anderson »  

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



Posts: 116

Re: Exporting a simple list...
Reply #2 - Nov 19th, 2010, 8:33am
 
Thanks Mark!

One more question...

What if want to export my container's children and grandchildren?

I'm sorry for the questions and I do love figuring this stuff out on my own, but I'm suppose to turn in this list soon.

Thanks again!
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Exporting a simple list...
Reply #3 - Nov 19th, 2010, 9:53am
 
Do you want to export the children and grandchildren interchangeably?  If so, replace ^children with ^descendants.

Often, one wants to export the grandchildren as nested lists.  In that case, the children can export their children:

^value($Name)^      ^value($Quantity)^      £^value(format($ApproxValue,2))^

^if($ChildCount>0)^ ^children(SubsidiaryItem)
^endif^

Back to top
 
 
WWW   IP Logged
AGHorne
Full Member
*
Offline



Posts: 116

Re: Exporting a simple list...
Reply #4 - Nov 19th, 2010, 10:41am
 
Thank you very much for the help.

Random and basic question...

Sometimes I see export codes that have two (^) and sometimes I just see one.  Why?  

Back to top
 
« Last Edit: Nov 19th, 2010, 10:50am by AGHorne »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Exporting a simple list...
Reply #5 - Nov 19th, 2010, 11:04am
 
The method Mark B points out is an extension of the envelope/letter method, with still only 2 templates being used.  The difference is if any children of the original container have children, they are included using the same template. Like a set of Russian nesting dolls, the process drills down until there are no more children and so all descendants are exported.

The first container will presumably always have children so we can push the child test to the 'Item' template. We also need to alter how totals are calculated. Thus 'Page' becomes:
Code:
Items

Name	Quantity	Approximate Value (£)

^children(Item)^

Total Items: ^value($DescendantCount)^
Total Number of pieces: ^value(sum(descendant,$Quantity))^
Total Value: £^value(
format(sum(descendant,($Quantity * $ApproxValue)),2))^
 


Whilst 'Item' becomes:
Code:
^value($Name)^	^value($Quantity)^	£^value(format($ApproxValue,2))^
^if(ChildCount > 0)^^children(Item)^
^endIf^ 



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: Exporting a simple list...
Reply #6 - Nov 19th, 2010, 11:08am
 
The closing ^ on export codes is optional. If omitted, Tinderbox will assume where the code finishes. If you don't know how Tinderbox decides closures, I'd advise adding an ending ^ as it lessens the chance of unexpected outcomes. For this reason I tend to always use closures in  codes examples intended for use by others. Bottom line, the choice is yours.
Back to top
 
« Last Edit: Nov 19th, 2010, 11:09am by Mark Anderson »  

--
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: Exporting a simple list...
Reply #7 - Nov 19th, 2010, 12:21pm
 
Here is a demo of the second version with one extra tweak.  If an item has a $ApproxValue of 0, the item's name is made a heading, using $Name and a colon only. See here.
Back to top
 
« Last Edit: Nov 19th, 2010, 12:22pm by Mark Anderson »  

--
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: Exporting a simple list...
Reply #8 - Mar 23rd, 2012, 6:01pm
 
Off-Topic replies have been moved to this Topic.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print