Edit

Selections

When using MoneyWorks, you see (and operate on) a “selection” of records. The visual representation of these are the lists, where the records that you can see in a list represent the “found set”. If you search the list, you will get a new “found set”. When you highlight one or more items in the list, you have a “highlighted selection”.

MoneyWorks allows you to create and use selections programmatically, where a selection is basically the stored results of some search. These can be created and used in both reports and scripts. Judicious use of such selections can make running reports substantially faster. Because selections are stored (at least temporarily), they can be reused without needing to repeat the search, which is relatively expensive.

Selections created by a report can also be passed by the report back to a Datacentre server. You will need to do this for any report that relies on some selection on your screen, as the Datacentre server cannot see what you are doing in a list window1.

A selection is made by using the CreateSelection function, to which you pass the MoneyWorks table name, and a search expression, e.g.

CreateSelection("transaction", "NameCode=`SPRING`", "TransDate")

creates a selection of all transactions which have a namecode of “SPRING”, and sorts it by the transaction date. The following report cell creates a selection dsel, which contains the detail lines of all posted sales invoices:

dsel =createSelection("detail", "[transaction:status=`P` and type='DI@'][detail]")

This selection can then be used as the basis for creating other selections. For example, we might want to report on sales of all products whose category1 is “Bronze”. So we can step through the Bronze products, then find the sales invoice lines for each one by creating a new selection, based on dsel and the product (meaning we don’t have to repeat the expensive search for the sales invoice lines for each product):

    foreach p in product where "category1 = `BRONZE`"
        mysel=IntersectSelection(dsel, "detail.stockcode ='" + p.code + "'")

We can then work through the new selection to do whatever we want to:

foreach d in detail mysel

The search expression can be a relational search or a simple one. It may also be a meta-search mnemonic from the list below:

"*highlighted" or "**"highlighted records in the main list for the table
"*found" or "*f"found records in the main list for the table
"*foundorall"found if any, or all if none found
"*"highlighted, if any; else found, if any; else all.

Note: When you create a selection in this manner, any records in the selection are locked for deletion (so that other users can’t destroy the selection under your feet). For this reason, you should not keep selections for longer than you need (they will automatically be discarded when the report or script is completed.


1  If you don't send the selection to Datacentre, the report will need to run on your machine, which will be significantly slower because of the large number of network requests it will probably need to make.