Differences

This shows you the differences between two versions of the page.

Link to this comparison view

datasettag [2016/09/22 02:35] (current)
Line 1: Line 1:
 +===== DataSet Tag=====
 +Dataset tag defines a data set which stores rows of data to be retrieved later by mscript function [[http://​testoptimal.com/​javaDoc/​reference/​com/​webmbt/​plugin/​MbtScriptExecutor.html#​getData%28java.lang.String%29 | $getData('​dsID','​fieldName'​)]].
 +
 +Before the //dataset// can be used, it must be declared and populated data from a data source.
 +
 +Example model: [[http://​testoptimal.com/​example/​Example_DataSet.zip | Example_DataSet]]
 +
 +----
 +==== Declare DataSet ====
 +The syntax to declare a dataset is:
 +
 +    <dataset id="​datasetid"​ db="​dbid"​ mode="​replace/​append"​ autorewind="​true/​false"/>​
 +
 +//​autorewind//​ attribute is used to automatically start at the first row when all rows have been retrieved.
 +
 +The //mode// attribute is used to append the new data to the data set or to clear the old data and replace them with the new data.
 +
 +Although //dataset// tag may be placed any mscript triggers, it is most often placed in //​MbT_Trigger//​ which is executed at the beginning of the model execution and it is executed only once per model execution.
 +
 +If //dataset// tag is executed multiple times, the recent execution overrides the previous.
 +
 +Once //dataset// is declared you can populate //dataset// with the data from external data sources.
 +
 +----
 +==== Load DataSet ====
 +There are three ways to populate the data set with rows of data.
 +
 +  * //sql// - use [[sqlTag|sql tag]] to declare the sql statement to be used to retrieve the data from jdbc data source to populate this data set.  [[[sqlTag |sql tag]] must be nested within //dataset// tag.
 +  * //rowdata// tag - use [[rowdataTag|rowdata tag]] to explicitly populate one row of data into this data set. [[rowdataTag|rowdata tag]] must be nested within //dataset// tag.  Add one [[rowdataTag|rowdata tag]] to add one row of data.
 +  * [[Read From File, Excel, Java, URL|other sources]] - you may populate //dataset// from other sources including csv file, tsv (tab separated) file and Excel workbootk/​sheets,​ url or custom java code.
 +
 +
 +Before you can use //​dataset//,​ you must call by calling mscript function [[http://​testoptimal.com/​javaDoc/​reference/​com/​webmbt/​plugin/​MbtScriptExecutor.html#​loadFromDataSource%28java.lang.String...%29 | $loadFromDataSource('​dsID','​param1',​...)]].
 +
 +----
 +==== Navigate DataSet====
 +
 +When you first loaded the dataset, it's positioned at first row (row 0). 
 +
 +Call mscript function [[http://​testoptimal.com/​javaDoc/​reference/​com/​webmbt/​plugin/​MbtScriptExecutor.html#​getData%28java.lang.String%29 | $getData('​dsID','​fieldName'​)]] to retrieve a specific field at the current row of the dataset.
 +
 +Call mscript function [[http://​testoptimal.com/​javaDoc/​reference/​com/​webmbt/​plugin/​MbtScriptExecutor.html#​nextDataSetRow%28java.lang.String,​%20java.lang.String%29 | $nextDataSetRow('​dsID'​)]] to advance move dataset to the next row.
 +
 +----
 +==== Retrieve Data Field ====
 +Once the dataset is positioned at the desired index, you can call out each field on the current row using MScript function $getData (...), for example:
 +
 +  $getData ('​myDS','​F1'​) or
 +  $getData ('​myDS:​F1'​)
 +  ​
 +Just like other MScript functions, you may nest call like:
 +  $getData ('​$getData ('​myDS:​F1'​)_x','​F22'​)
 +  ​
 +In the above example, the inner $getData ('​myDS:​F1'​) retrieves the value of column //F1// from dataset //myDS//. The value returned is then concatenated with //_x// to form the dataset name for the outer $getData (...).
 +
 +You may retrieve data using a short hand format //​[dsName:​colName]//​ just like calling out system and user variables:
 +  [myDS:F1]
 +  ​
 +Obviously your dataset name must not contain semi-colon ":"​ in order to use this short hand syntax.
 +
  
Print/export
QR Code
QR Code datasettag (generated for current page)