Augmenting Datasources via “CreateContent.lua”

Incoming data can be manipulated using a script which is executed immediately after EasyCatalog loads data from a data source, but before additional processing. The ‘createcontent.lua’ script, when located in the data sources scripts folder, is called immediately before loading data. It gets passed a ‘records’ variable which is a RECORDSET object representing the raw data from the data source.

The script has the ability to add records, remove fields, rename fields and set field content. Potentially this could incorporate data from other sources into a single set of data, or to pull different language fields based on data source options.

For example:

simple example.xls

field 1field 2field 3

When loaded into EasyCatalog, with field 1 as a key, it looks like:

Using the following ‘createcontent.lua’ script:

The result after synchronizing is:

Make sure the field type of “Tabular Field” is set to be a tabular field, with “Command Script” as the source.

Notice the indicators on the fields which didn’t originate from the original data. Fields created in this way are treated as regular fields, with the exception of tabular fields which are stored in binary format within the snapshot file.

The advantage of this technique over using ‘createformattedcontent.lua’ is that data is manipulated before its loaded, so content changes affect the actual content of a field. It also doesn’t impact on the rebuilding of formatted content, so only happens each time the data is synchronized.  In addition to this, content changes (updated, deleted) can be indicated.