Jint: Difference between revisions

From Data Islands
(jint)
 
(example scripts)
Line 33: Line 33:


}
}
<nowiki>'''Some Examples'''</nowiki>
a. Accessing Column names
var table = di.querydb("select top 2 * from customers where hasregionflag='Y'");
for(var x=0;x<table.Columns.Count;x++)
{
   var _colName= table.Columns[x].ColumnName;
di.display("colname="+_colName);
}
b. Altering data before pushing

Revision as of 13:32, 3 August 2022

You can write and run javascript commands allowing you to iterate over a dataset (querydb) and automate region creation and various other commands.


The command is

>jint

to switch into javascript coding mode.

You can write a js file and execute using the file path parameter

> jint "pathtofile/file.js"


Sample script that queries a "customers" table for any customers that have a flag set and then for each of those it creates a data island "region" and pushes up the customers "orders" to an island.


var result = di.connect("youraccount","yourpassword");

var table = di.querydb("select top 2 * from customers where hasregionflag='Y'");

for(var x=0;x<table.Rows.Count;x++)

{

   var fieldValue = table.Rows[x]['CustomerID'];

   di.addregion(fieldValue);

   var qorders=di.querydb("select * from Orders where customerid='"+fieldValue+"'");

   di.push("orders");

}


'''Some Examples'''

a. Accessing Column names

var table = di.querydb("select top 2 * from customers where hasregionflag='Y'");

for(var x=0;x<table.Columns.Count;x++)

{

   var _colName= table.Columns[x].ColumnName;

di.display("colname="+_colName);

}


b. Altering data before pushing