Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Exporting from Tinderbox >> Exporting a simple list...
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1290142656

Message started by AGHorne on Nov 18th, 2010, 11:57pm

Title: Exporting a simple list...
Post by AGHorne on 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...


Title: Re: Exporting a simple list...
Post by Mark Anderson on 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.

Title: Re: Exporting a simple list...
Post by AGHorne on 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!

Title: Re: Exporting a simple list...
Post by Mark Bernstein on 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^


Title: Re: Exporting a simple list...
Post by AGHorne on 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?  


Title: Re: Exporting a simple list...
Post by Mark Anderson on 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^



Title: Re: Exporting a simple list...
Post by Mark Anderson on 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.

Title: Re: Exporting a simple list...
Post by Mark Anderson on 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.

Title: Re: Exporting a simple list...
Post by Mark Anderson on Mar 23rd, 2012, 6:01pm

Off-Topic replies have been moved to this Topic.

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.