Custom JavaScript Functions

Modified on Wed, 11 Jun at 1:38 PM


FileUtils functions


Return type

Method description

Boolean

fileExists(String filePath)

Verifies whether a specified file exists or not. 

Parameters

filePath – Specify complete file path with file name and extension. 

Return

Returns true if the file exists, otherwise returns false.  

Example

FileUtils.fileExists(“/home/user/Desktop/Sales.csv”);

Boolean

moveFile(String srcFilePath, String destFolderPath , boolean overwriteOrCopy)

Moves source file to the given destination location.

Note : This method can throw an Exception when a file cannot be moved due to some error. This exception error is useful for error reporting and to diagnose why a file cannot be moved.

Parameters

srcFilePath – Specify complete file path with filename and extension for the file which you want to move.

destFolderPath – Specify destination folder path where you want to move the file.

overwriteOrCopy -  Specify true when a file with the same file name already exists in the destination folder and you do not want to overwrite it and create a new copy. New file name will have “Copy_” prefix for the file name. Specify false when you want to overwrite an existing file.

Return

Returns true if the file is moved successfully, or returns false if failed to move the file.

Example

FileUtils.moveFile(“/home/user/Desktop/Sales.csv” , “/home/user/Documents/”, true);

 File []

getFileList(String folderPath,String extension)

Returns a list of all files for a given folder path. You can specify file extension when you want to get a file list for a specific extension. 

Parameters

folderPath – Specify a complete folder path for which you want to get a file list. 

extension – specify file extension to get a list of files with specific extension. Specify “*” for fetching all files in a folder.

Return

Returns File object array in specified folder for file(s) with given extension.

Example

FileUtils.getFileObjects(“/home/user/Desktop/” , “csv”); returns list of .csv files from specified folder

FileUtils.getFileObjects (“/home/user/Documents/” , “js”); returns list of .js files from specified folder

FileUtils.getFileObjects(“/home/user/Documents/” , “*”);returns list of all files from specified folder

String[]

getFileNameList(String folderPath,String extension)

Returns a list of all file names for a given folder path. You can specify file extension when you want to get a file list for a specific extension. 

Parameters

folderPath – Specify complete folder path for which you want to get file names list. 

extension – specify file extension to get a list of file names with specific extension. Specify “*” for fetching all files in a folder.

Return

Returns File names array in specified folder for file(s) with given extension.

Example

FileUtils. getFileNameList (“/home/user/Desktop/” , “csv”); returns list of .csv file names from specified folder

FileUtils. getFileNameList (“/home/user/Documents/” , “js”); returns list of .js file names from specified folder

FileUtils. getFileNameList (“/home/user/Documents/” , “*”);returns a list of all file names from the specified folder.

File

getFileObject(String filePath)

Returns file object for a specified file path.

Note : This method can throw an Exception when a file object cannot be created due to some error. This exception error is useful for error reporting and to diagnose why a file cannot be created.


Parameters

filePath – Specify complete file path with file name and extension to get File object.

Return

Returns file object for specified file path. If there is any error, it will return NULL.

Example

FileUtils. getFileObject (“/home/user/Desktop/Sales.csv”);

Boolean

deleteFile(String filePath)

Removes a specified file.

Note : This method can throw an Exception when a file cannot be deleted due to some error. This exception error is useful for error reporting and to diagnose why a file cannot be deleted.

Parameters

filePath – Specify complete file path with file name and extension which you want to delete.

Return

Returns true if the file is removed successfully.  Returns false if failed to remove the file.  

Example

FileUtils.deleteFile(“/home/user/Desktop/Sales.csv”);

Boolean

copyFile(String srcFilePath, String destFolderPath  , boolean overwriteOrCopy)

Copies a specific file to the given destination folder path.

Note : This method can throw an Exception when a file cannot be copied due to some error. This exception error is useful for error reporting and to diagnose why a file cannot be copied.

Parameters

srcFilePath – Specify complete file path with filename and extension for the file which you want to copy.

destFolderPath – Specify destination folder path where you want to copy files.

overwriteOrCopy -  Specify true when a file with the same file name  already exists in the destination folder and you do not want to overwrite it and you want  to create a new copy of a file. New file name will have “Copy_” prefix in the file name. Specify false when you want to overwrite existing file.

Return

Returns true if the file is copied successfully or false if failed to copy.

Example

FileUtils.copyFile(“/home/user/Desktop/Sales.csv” , “/home/user/Documents/”, true);

Boolean

renameFile(String filePath,String newFilename)

Rename a specific file with a new name.

Note : This method can throw an Exception when a file cannot be renamed due to some error. This exception error is useful for error reporting and to diagnose why a file cannot be renamed.

Parameters

filePath – Specify complete file path with file name and extension which you want to rename.

newFilename – Specify new file name(with extension) which you want to rename.

Return

Returns true if file renamed successfully. Otherwise returns  false if failed to rename file.

Example

FileUtils.renameFile(“/home/user/Desktop/Sales.csv” , “Sales_test.csv”);


Boolean

copyFolder(String srcFolderPath, String destFolderPath  , boolean overwriteOrCopy)

Copies source folder to given destination folder path including all sub folders.

Note : This method can throw an Exception when a folder cannot be copied due to some error. This exception error is useful for error reporting and to diagnose why a file cannot be copied.

Parameters

srcFilePath – Specify complete folder path which you want to copy.

destFolderPath – Specify destination folder path where you want to copy the folder.

overwriteOrCopy - Specify true when the folder with the same folder name  already exists in the destination folder and you do not want to overwrite it and want to create a new copy of the folder. New folder name will have “Copy_” prefix in the folder  name. Specify false when you want to overwrite an existing folder.

Return

Returns true if the folder is copied successfully. Otherwise returns false if failed to copy.

Example

FileUtils. copyFolder (“/home/user/Desktop/sales/” , “/home/user/Documents/”, true);

Boolean

moveFolder(String srcFolderPath, String destFolderPath  , boolean overwriteOrCopy)

Moves specified folder to given destination location.

Note : This method can throw an Exception when a folder cannot be moved due to some error. This exception error is useful for error reporting and to diagnose why a folder cannot be moved.

Parameters

srcFilePath – Specify complete folder path which you want to move.

destFolderPath – Specify destination folder path where you want to move the folder.

overwriteOrCopy - Specify true when the folder with the same name already exists in the destination folder and you do not want to overwrite it and want to create a new copy of the folder. New folder name will have “Copy_” prefix in the folder name. Specify false when you want to overwrite an existing folder.

Return

Returns true if the folder moved successfully. Otherwise returns false if failed to move.

Example

FileUtils.moveFolder(“/home/user/Desktop/sales/” , “/home/user/Documents/”, true);

Boolean

deleteFolder(String folderPath)

Removes the specified folder.

Note : This method can throw an Exception when a folder cannot be deleted due to some error. This exception error is useful for error reporting and to diagnose why a folder cannot be deleted.

Parameters

folderPath – specify the complete folder path which you want to delete.

Return

Returns true if the folder is removed successfully. Otherwise returns false if failed to remove the folder.  

Example

FileUtils.deleteFolder(“/home/user/Desktop/Sales”);

Boolean

renameFolder(String folderPath,String newFoldername)

Rename specified folder with new name.

Note : This method can throw an Exception when a folder cannot be renamed due to some error. This exception error is useful for error reporting and to diagnose why a folder cannot be renamed.

Parameters

filePath – Specify complete folder path which you want to rename.

newFoldername – Specify new folder name which you want to rename.

Return

Returns true if the folder is renamed successfully. Otherwise returns false if failed to rename the folder.

Example

FileUtils. renameFolder (“/home/user/Desktop/sales” , “Sales_test”);


Boolean

createFolder(String parentFolderPath , String newFolderName)

Creates a new folder in the specified folder path.

Note : This method can throw an Exception when a folder cannot be created due to some error. This exception error is useful for error reporting and to diagnose why a folder cannot be created.

Parameters

parentFolderPath – Specify complete folder path in which a new folder will be created.

newFolderName – Specify new folder name that you want to create.

Return

Returns true if the folder is created successfully. Otherwise returns false if failed to create the folder.

Example

FileUtils. createFolder (“/home/user/Desktop/” , “sales”);

String

getSmartenServerSharedFolderPath()

Returns the Smarten shared folder path which is configured in Smarten general configuration.


Smarten Shared folder is a shared directory on the Smarten server. Smarten shows files and folders of this shared folder while creating a file data source, and uses files in this shared folder as file datasource.

By default, /data folder on the Smarten server is your Smarten shared folder. 
You can change the Smarten shared folder path from the Smarten administration panel.

Returns

Returns shared folder path string.

Example

FileUtils. getServerSharedFolderPath ();

String

getSmartenPublishingFolderPath()


Returns the Smarten publishing  folder path which is configured in Smarten general configuration.


Smarten publishing folder is a folder on the Smarten server that is used by delivery and publishing schedulers to publish BI objects export files . 

By default, /data folder on the Smarten server is your Smarten publishing folder. 
You can change the Smarten publishing folder path from the Smarten administration panel.



Returns

Returns publishing folder path string.


Example

FileUtils. getPublishingFolderPath();

boolean

zipFiles(String[] filePaths , String parentFolder , String zipFileName )

Create a new zip file based on specified file paths.


Parameters

filePaths - specifies a list of files or folder paths which need to be included in a zip file.

parentFolder - specifies folder path at which zip file is to be placed.

zipFileName - name of zip file will be created in “parentFolder” path as specified in argument2.


Returns

Returns true if zip file created successfully for specified file paths , false otherwise.


Example

var paths = [“/home/user/Desktop/sales1.csv” , “/home/user/Desktop/backup”“/home/user/Desktop/sales2.csv” , “/home/user/Desktop/sales3.csv” , “/home/user/Desktop/data” ];

FileUtils.zipFiles(paths,“/home/user/Documents/” , “temp.zip” ); will create new zip file with name temp.zip at path /home/user/Documents/ which includes 3 files and 2 folders as specified in argument.

boolean

unzipFile(String filePath)

Unzip file and create a new folder.

Parameters

filePath - specifies complete path for zip file which needs to be extracted.

Returns

Returns true if zip file extracted successfully for specified file paths , false otherwise.

Example

FileUtils.unzipFile(“/home/user/Documents/temp.zip” ); will create a new folder temp on /home/user/Documents/ with extracted files.


File object functions

Return type

Method description

String

getFilePath()

Returns path of file object.

Returns

Returns string form of abstract pathname.

Example

var fileObject = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.getFilePath();  returns the string “/home/user/Desktop/Sales.csv”.

String

getFileName()

Returns name of file with extension.

Returns

Returns name of file with extension.

Example

var fileObject = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.getFileName(); returns string “Sales.csv”.

Boolean

canExecute()

Check, if application(Script) has permission to execute this file

Note : This method can throw an Exception if the security manager exists and denies access.

Returns

true if and only if the application is allowed to execute the file; false otherwise.

var fileObject = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.canExecute();

Boolean

canRead()

Check, if application(Script) has permission to read this file.

Note : This method can throw an Exception if the security manager exists and denies access.

Returns

true if and only if the file can be read by the application; false otherwise.

var fileObject = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.canRead();

Boolean

canWrite()

Check, if application(Script) has permission to write this file.

Note : This method can throw an Exception if the security manager exists and denies access.

Returns

true if and only if the application is allowed to write to the file; false otherwise.

var fileObject = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.canWrite();

Boolean

isDirectory()

Check, whether the file is a directory.

Note : This method can throw an Exception if the security manager exists and denies access.

Returns

true if and only if the file is a directory; false otherwise.


Example

var fileObject1 = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

var fileObject2  = FileUtils.getFileObject(“/home/user/Desktop/”);

fileObject1 and fileObject2  is the file type object being used in the script.

fileObject1.isDirectory (); returns false.

fileObject2.isDirectory(); returns true.

Boolean

isFile()

Check, whether the file is a normal file not a directory.

Note : This method can throw an Exception if the security manager exists and denies access.

Returns

true if and only if the file is a normal file; false otherwise.


Example

var fileObject1 = FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

var fileObject2 = FileUtils.getFileObject(“/home/user/Desktop/”);

fileObject1 and fileObject2  is the file type object being used in the script.

fileObject1.isFile(); returns true.

fileObject2.isFile(); returns false.

String

getParentFolderPath()

Returns the pathname string of parent, or null if this pathname does not name a parent directory.


Returns

The pathname string of the parent directory.


Example

var fileObject= FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.getParentFolderPath(); returns string “/home/user/Desktop”.

Date

getLastModifiedDatetime()

Returns the Date at which the file was last modified.


Returns

Returns the Date at which the file was last modified.

var fileObject= FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.getLastModifiedDatetime();

Number

fileSizeInBytes()

Returns the length of the file.


Returns

The length, in bytes, of the file, or 0 if the file does not exist.

var fileObject= FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.fileSizeInBytes();

String

getMimeType()

Returns mime type of file.


Returns

Returns mime type of file. Valid values are “text/plain” , “text/html” ,”application/json”,”images/png” etc.


Example

var fileObject= FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject. getMimeType(); returns “text/csv”.

String

getFileExtention()

Returns the extension of the file.


Returns

Returns the extension of the file.


Example

var fileObject= FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.getFileExtention(); returns “csv”.

String

getEncoding()

Returns encoding of the file.


Returns

Returns the encoding of the file.


Example

var fileObject= FileUtils.getFileObject(“/home/user/Desktop/Sales.csv”);

fileObject is the file type object being used in the script.

fileObject.getEncoding(); returns “UTF-8”.







DatasetUtil functions


Return type

Method description

DataTable

createDataTableFromTextFile(String filePath, String isFirstRowHeader, String textQualifier, String columnSeparator, String charset, String autoIdentifySchema,String rowSeparator,String dateFormat)

Create a DataTable from a given csv file based on applied options.

 

Parameters

filePath – complete file path of text file.If multiple files are there need to use comma file path for each file .For example “/home/user/Desktop/Sales.csv,/home/user/Desktop/Sales2025.csv”.To specifies set of files in particular folder expression string can be passes.For example to get data from all files name starts from Sales we can use “/home/user/Desktop/Sales*”.

isFirstRowHeader  - option for specifying the first row as header.

textQualifier – text qualifier string.

columnSeparator – column separator string.

charset – charset of file.

autoIdentifySchema– option for automatic identifying  schema or not.

rowSeparator – row separator string.

dateFormatForAutoIdentifySchema - date or timestamp format which is used in identifying file schema automatically. Applicable only if autoIdentifySchema parameter is “true”.If parameter value in null or empty, ‘yyyy-MM-dd’ format will be used by default.

 

Return

Returns DataTable for given csv file.

 

Example

DatasetUtil.createDataTableFromTextFile(“/home/user/Desktop/Sales.csv,/home/user/Desktop/SalesData/*” , “true” , “’” , “,” ,”UTF-8”,”true”,”\n”,null);

DatasetUtil.createDataTableFromTextFile(“/home/user/Desktop/Sales.csv,/home/user/Desktop/Sales2025.csv” , “true” , “’” , “;” ,”ANSI”,”false”,”\n” , “dd-MM-yyyy”);

DataTable

createDataTableFromExcelFile(String filePath, String firstRowAsColumn, int skipFirstRows,String dateFormat)

Create DataTable from excel file with specified option.

 

Parameters

filePath – complete file path of excel file.If multiple files are there need to use comma file path for each file .For example “/home/user/Desktop/Sales.xls,/home/user/Desktop/Sales2025.xls”.To specifies set of files in particular folder expression string can be passes.For example to get data from all files name starts from Sales we can use “/home/user/Desktop/Sales*”.

firstRowAsColumn - option for specifying the first row as header.

skipFirstRows – no rows to skip in excel file.

dateFormat - date or timestamp format for data in file.

 

Return

Returns DataTable for a given excel file.

 

Example

DatasetUtil.createDataTableFromExcelFile(“/home/user/Desktop/Sales.xls” , “true” , 0 , null);

DatasetUtil.createDataTableFromExcelFile(“/home/user/Desktop/Sales.xls,/home/user/Desktop/Sales2025.xls” , “true” , 5 , “dd-MM-yyyy”);

 

DataTable

createDataTableFromJSONFile(String filePath, String treatEmptyValuesAsNulls, String multiLine, String charset)

Create a DataTable from a given json file based on applied options.

 

Parameters

filePath – complete file path for json file.If multiple files are there need to use comma file path for each file .For example “/home/user/Desktop/Sales.json,/home/user/Desktop/Sales2025.json”.To specifies set of files in particular folder expression string can be passes.For example to get data from all files name starts from Sales we can use “/home/user/Desktop/Sales*”.

treatEmptyValuesAsNulls - option for treating empty value as null.

multiLine – option for multi line data contains for json file

charset – charset of file.

 

Return

Returns DataTable for given json file.

 

Example

DatasetUtil. createDataTableFromJSONFile(“/home/user/Desktop/Sales.json,/home/user/Desktop/SalesData/*” , “true” , “true” , “UTF-8”);

DataTable

createDataTableFromXMLFile(String filePath , String rowTag , double samplingRatio , String dateFormat)

Create a DataTable from a given xml file based on applied options.

Parameters

filePath – complete file path for xml file.If multiple files are there need to use comma file path for each file .For example “/home/user/Desktop/Sales.xml,/home/user/Desktop/Sales2025.xml”.To specifies set of files in particular folder expression string can be passes.For example to get data from all files name starts from Sales we can use “/home/user/Desktop/Sales*”.

rowTag – row tag of given xml file

samplingRatio – sample ration.

dateFormat - date or timestamp format for data in file.

 

Return

Returns DataTable for given xml file.

 

Example

DatasetUtil.createDataTableFromXMLFile(“/home/user/Desktop/Sales.xml,/home/user/Desktop/SalesDataXml/*l” , “data” , 0.5 ,”dd-MM-yyyy” );

DataTable

createDataTableFromDatabase(String driverClass, String url, String query, String userName, String passWord)

Create DataTable for database query.

 

Parameters

driverClass – driver class for database

url – url string for database

query – database query.

userName – username.

passWord – password.

 

Return

Returns DataTable for given database parameter.

Example

DatasetUtil.createDataTableFromDatabase(“com.mysql.jdbc.Driver” , "jdbc:mysql://localhost:3306/test", “true” , “select * from sales_records” , “root” , “root”);

DatasetUtil. createDataTableFromDatabase (“oracle.jdbc.driver.OracleDriver” , " jdbc:oracle:thin:@localhost:1521:xe", “true” , “select * from sales_records” , “system” , “system”);

 

DataTable

createDataTableFromDatabaseDataSource(String datasourceName,  String query)

Create DataTable for database query.

Parameters

datasourceName – valid datasource name created in smarten.

query – database query.

 

Return

Returns DataTable for given database parameter.

Example

DatasetUtil.createDataTableFromDatabaseDataSource(“mysql_datasource” , “select * from sales_records”);

DataTable

createDataTableFromArray(Object[][] data,String[][] schema)

Create a DataTable based on specified data and schema.

Parameters

data– data as 2D object array

schema – column schema

 

Return

Returns DataTable for given object data and specified schema.

Example

var arr =[[“Health Drinks” , "Strawberry",2 , 45.67], [“Alcoholic Drinks”,"Beer",4 , 787.45], [“Alcoholic Drinks”,"Wine ",4 , 787.45],[“Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  , ["ProductName" , "STRING"] , ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

DatasetUtil. createDataTableFromArray (arr , schema);

DataTable

createDataTableFromSmartenDataset(String datasetId)

Create dataTable from smarten dataset from dataset id.

Parameters

datasetId - Id of smarten dataset  for which dataset is to be returned.

Returns

Returns a dataset created in smarten for given id.

Example

DatasetUtil.createDataTableFromSmartenDataset(“189dab432d7.dtst”);

 

void

refreshSmartenDataset(String datasetId , boolean isFromScratch)

Refresh smarten dataset for given id.

Parameters

datasetId - Id of smarten dataset need to refresh.

isFromScratch - if true refreshed as incremental otherwise refresh from scratch. 

Example

DatasetUtil.refreshSmartenDataset(“189dab432d7.dtst” , false);

  

DataTable

removeDuplicateRows(DataTable dataTable)

Removes all duplicate rows from specified dataTable and returns new dataTable.

 

Parameters

dataTable–  dataTable for which distinct dataTable is returned.

 

Return

Return dataTable with distinct rows for given dataTable.

 

Example

var arr =[[“Health Drinks” , "Strawberry",2 , 45.67], [“Alcoholic Drinks”,"Wine",4 , 787.45], [“Alcoholic Drinks”,"Wine ",4 , 787.45],[“Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  , ["ProductName" , "STRING"] , ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil. createDataTableFromArray (arr , schema);

DatasetUtil.removeDuplicateRows(dataTable);  returns a dataTable with 3 rows removing 1 duplicate row(“Alcoholic Drinks”,"Wine",4 , 787.45);

DataTable

createDataTableFromJSONString(String jsonString, String treatEmptyValuesAsNulls, String multiLine, String charset)

Create a DataTable from a given json file based on applied options.

 

Parameters

jsonString– json string for creating datatable.

treatEmptyValuesAsNulls - option for treating empty value as null.

multiLine – option for multi line data contains for json file

charset – charset of file.

 

Return

Returns DataTable for given json string.

 

Example

DatasetUtil. createDataTableFromJSONString(“” , “true” , “true” , “UTF-8”);





DataTable functions

Return type

Method description

Void

transformColumnDatatype(String dataTableColumnName , String targetDatatype ,  String[] targetDateFormat)

Convert datatype of specified column to new datatype in DataTable.


Parameters

dataTabletColumnName – dataTable column name.

targetDatatype – new data type.(Possible values are STRING , INT , LONG , FLOAT , DOUBLE , DATE etc).

targetDateFormats – This parameter is used when targetDatatype is DATE only for other type it should be null.


Example

dataTable.transformColumnDatatype(“Emp_ID”,  “INT” , null);

dataTable.transformColumnDatatype(“Date”,  “DATE” , [“dd-MMM-yyyy hh:mm”]);

dataTable.transformColumnDatatype(“Date”,  “DATE” , [[“dd-MMM-yyyy hh:mm”],[“yyyy-MM-dd hh:mm”]]);

Boolean

renameColumn(String existingColumnName , String newColumnName)

Rename dataTable column with new name.


Parameters

existingColumnName – dataTable column name needs to rename

newColumnName – new column name.


Returns

true if column name is renamed successfully , false otherwise.


Example

var arr =[[“Health Drinks” , "Strawberry",2 , 45.67], [“Alcoholic Drinks”,"Beer",4 , 787.45], 

[“Alcoholic Drinks”,"Wine ",4 , 787.45], [“Confectionary”,"Mints",6 ,567.4][“Bakery”,"Cake",7,967.4] ];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] , 

                          ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil. createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


dataTable.renameColumn(“ProductCategory” , “Category_Name”);


Category_Name   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4



Object[][]

getColumnsDataInArray(String[] dataTableColumnNames)

Returns object array based on specified columns  in DataTable.


Parameters

dataTableColumnNames – specify one or more dataTable column names for which you want to fetch data from dataTable.


Returns

Returns 2D object array .


Example

var arr =[[“Health Drinks” , "Strawberry",2 , 45.67], [“Alcoholic Drinks”,"Beer",4 , 787.45], 

[“Alcoholic Drinks”,"Wine ",4 , 787.45], [“Confectionary”,"Mints",6 ,567.4][“Bakery”,"Cake",7,967.4] ];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] , 

                          ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil. createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

var  columnValuesArray = dataTable.getColumnDataInArray([“ProductName” , “SalesPrice”]); returns  array  as below 


[["Strawberry",45.67] ,

 [“Beer” , 787.45],

[“Wine” ,787.45] , 

[“Mints” , 567.4]

[“Cake” ,  967.4]].

Object[][]

getDataTableDataInArray()

Returns  object array for all columns in DataTable.


Returns

Returns 2D object array .


Example


var arr =[   [“Health Drinks” , "Strawberry",2 , 45.67],  [“Alcoholic Drinks”,"Beer",4 , 787.45], 

                    [“Alcoholic Drinks”,"Wine ",4 , 787.45] ,  [“Confectionary”,"Mints",6 , 567.4]  ];

var schema = [["ProductCategory" , "STRING"]  , ["ProductName" , "STRING"] , 

                          ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil. createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable= dataTable.getSubDataTable([“ProductName” , “SalesPrice” ]);

dataTable.getDataTableDataInArray(); returns array as below 


 [["Strawberry",45.67] , 

  [“Beer” , 787.45],

  [“Wine” ,787.45] , 

  [“Mints” , 567.4]].


Object

getCellValue(int rowIndex , String dataTableColumnName)

Returns object for cell at given row index and column name.


Parameters

rowIndex – row index.

dataTableColumnName – dataTable column name.


Returns

Returns a cell object.


Example

var arr =[   [“Health Drinks” , "Strawberry",2 , 45.67],  [“Alcoholic Drinks”,"Beer",4 , 787.45], 

                    [“Alcoholic Drinks”,"Wine ",4 , 787.45] ,  [“Confectionary”,"Mints",6 , 567.4]  ];

var schema = [["ProductCategory" , "STRING"]  , ["ProductName" , "STRING"] , 

                          ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable = DatasetUtil. createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


dataTable.getCellValue(2,“ProductName”);  returns “Beer”.


Object[]

getRowDataInArray(int rowIndex)

Returns rows at a given index.


Parameters

rowIndex – row index.


Returns

Returns dataTable row as object array.


Example

var arr =[   [“Health Drinks” , "Strawberry",2 , 45.67],  [“Alcoholic Drinks”,"Beer",4 , 787.45], 

                    [“Alcoholic Drinks”,"Wine ",4 , 787.45] ,  [“Confectionary”,"Mints",6 , 567.4]  ];

var schema = [["ProductCategory" , "STRING"]  , ["ProductName" , "STRING"] , 

                          ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable = DatasetUtil. createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


dataTable.getRowDataInArray(2); returns array [“Alcoholic Drinks”,"Beer",4 , 787.45].


String

getSchema()    

Returns all columns with their type in DataTable


Returns

Returns json string of dataTable schema which includes column name and data type.


Example

var arr =[[“Health Drinks” , "Strawberry",2 , 45.67],

                [“Alcoholic Drinks”,"Beer",4 , 787.45], 

                [“Alcoholic Drinks”,"Wine ",4 , 787.45],

                [“Confectionary”,"Mints",6 , 567.4]];


var schema = [["ProductCategory" , "STRING"]  , 

                          ["ProductName" , "STRING"] , 

                          ["SalesQty" , "INT"], 

                          ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil. createDataTableFromArray (arr , schema);

var schema = JSON.parse(dataTable.getSchema());

where schema is array


 [

{"name":"ProductCategory" , "type":"STRING"},

{"name":"ProductName" , "type":"STRING"},

{"name":"SalesQty" , "type":"INTEGER"},

{"name":" SalesPrice " ,  "type":"DOUBLE"}

].



DataTable

union(DataTable otherDataTable)

Union current  dataTable with other dataTable.


Parameters

otherDataTable – other dataTable for union.


Returns

Returns a new dataTable for union of the current dataTable with another dataTable


Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   ,

                     [“Alcoholic Drinks”,"Beer",4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,   

                     [“Confectionary”,"Mints",6 , 567.4]];

var arr2 =[        [“Bakery” , "Cake",2 , 45.67]     ,       

                          [“Health Drinks” , "Strawberry",2 , 45.67],            

                          [“Alcoholic Drinks”,"Whisky",5 , 787.45]];


var schema = [["ProductCategory" , "STRING"]  ,

                          ["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

var otherDataTable = DatasetUtil.createDataTableFromArray (arr2 , schema);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


otherDataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Bakery

Cake

2

45.67

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Whisky

5

787.45



dataTable.union(otherDataTable); returns dataTable with 7 rows 4 from dataTable and 3 from otherDataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

2

45.67

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Whisky

5

787.45



DataTable

intersect(DataTable otherDataTable)

Intersect current dataTable with other dataTable.

Parameters

otherDataTable – other dataTable for intersection.

Returns

Returns new dataTable for intersection of current dataTable with other dataTable. 

Example

var arr =[ [“Health Drinks” , "Strawberry",2 , 45.67] ,[“Alcoholic Drinks”,"Beer",4 , 787.45]   , 

                      [“Confectionary”,"Mints",6 , 567.4]];

var arr2 =[ [“Bakery” , "Cake",2 , 45.67],[“Health Drinks” , "Strawberry",2 , 45.67]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

var otherDataTable = DatasetUtil.createDataTableFromArray (arr2 , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4

otherDataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Bakery

Cake

2

45.67

Health Drinks

Strawberry

2

45.67

dataTable.intersect(otherDataTable); returns dataTable as below.

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67


DataTable

except(DataTable otherDataTable)

Returns the dataTable for all rows of the first dataTable that do not appear in the second dataTable.

Parameters

otherDataTable – other dataTable for except.

Returns

Returns a dataTable that contains the rows of the current dataTableminus all the rows of other dataTable.

Example

var arr =[[“Health Drinks”,"Strawberry",2] ,[“Alcoholic Drinks”,"Beer",4]  [“Confectionary”,"Mints",6]];

var arr2 =[        [“Bakery” , "Cake",2 ]     ,   [“Health Drinks” , "Strawberry",2 ]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

var otherDataTable = DatasetUtil.createDataTableFromArray (arr2 , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

Health Drinks

Strawberry

2

Alcoholic Drinks

Beer

4

Confectionary

Mints

6

otherDataTable will be as below

ProductCategory   

ProductName  

SalesQty

Bakery

Cake

2

Health Drinks

Strawberry

2

dataTable.except(otherDataTable); returns dataTable as below.

ProductCategory   

ProductName  

SalesQty

Alcoholic Drinks

Beer

4

Confectionary

Mints

6


DataTable

join(DataTable otherDataTable, String[] joinConditions, int joinType)

Join current dataTable with other dataTable based on column condition and join type.

Parameters

otherDataTable – other dataTable for join.

joinConditions – specify join condition. Format for the condition is {columnName1}{operator}{columnName2}.Valid values for the operator are = , < , > , <= , >= and !=.For example “emp_id=emp_id” .

joinType – type of join.(Valid values are 0=CROSS , 1=INNER , 2=LEFT_OUTER , 3=RIGHT_OUTER )

Returns

Returns a new dataTable for join of current dataTable with other dataTable

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   ,

                     [“Alcoholic Drinks”,"Beer",4 , 787.45]   , 

                     [“Confectionary”,"Mints",6 , 567.4]];

var arr2 =[       [2,“Vuong Smith”]     ,      [4 ,“Heather Bruce”],            

                          [6 ,“Jason V Mehata”]];

var schema = [["ProductCategory" , "STRING"]  ,

                          ["ProductName" , "STRING"] ,

                          ["Emp_Id" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

Var schema2 = [["Emp_Id" , "INT"]  ,  ["EmployeeName" , "STRING"] ];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

var otherDataTable = DatasetUtil.createDataTableFromArray (arr2 , schema2);

dataTable will be as below

ProductCategory   

ProductName  

Emp_Id

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4

otherDataTable will be as below

Emp_Id

EmployeeName

2

Vuong Smith

4

Heather Bruce

6

Jason V Mehata

dataTable.join(otherDataTable,[“Emp_Id=Emp_Id”] , 1); returns below dataTable

ProductCategory   

ProductName  

Emp_Id

SalesPrice

EmployeeName

Health Drinks

Strawberry

2

45.67

Vuong Smith

Alcoholic Drinks

Beer

4

787.45

Heather Bruce

Confectionary

Mints

6

567.4

Jason Vmehata


Boolean

writeToCSV(String filePath, int mode, boolean writeHeader)

Write data from dataTable to specified csv file.

Note : This method can throw an Exception when a failed to write csv for a given dataTable due to some error. This is useful for error reporting and to diagnose why writing to csv failed.


Parameters

filePath – complete file path with file name and extension.

mode – write mode. valid values are 0=Overwrite , 1=Append).

writeHeader – option for write column name header as first line in output csv file.

Returns

Returns true if the file is written successfully or false if failed to write csv.  

Example

dataTable.writeToCSV(“/home/user/Desktop/Sales.csv” , 0 , true);

dataTable.writeToCSV(“/home/user/Desktop/Sales.csv” , 1 , false);



Boolean

writeToDatabase(String databaseType, String host, String port, String databaseName, String userName, String passWord,String tableName, String otherParameters,int mode)


Write data from the current dataTable to the database table based on specified parameters.


Note : This method can throw an Exception when a failed to write data to the database table due to some error. This is useful for error reporting and to diagnose why failed to write data to a database dataTable.


Parameters

databaseType – database type.

host – host url.

port – port.

databaseName – database name.

userName – username.

passWord – password.

otherParameters – other parameters for database.

mode – write mode. (Valid values are 0=Overwrite , 1=Append).


Returns

Returns true if write data to the database table successfully or false if failed to write data.  


Example

dataTable.writeToDatabase (“mysql” , "http://localhost", “3306” , “test_db” , “root” , “root”,”sales”,null,0);

dataTable.writeToDatabase (“oracle” , "http://localhost", “1521” , “test_db” , “system” , “system”,”sales”,null,0);


Boolean

writeToDatabaseDatasource(String datasourceName, String tableName,int mode)

Write data from the current dataTable to the database table for specified datasource.


Note : This method can throw an Exception when a failed to write data to the database table due to some error. This is useful for error reporting and to diagnose why failed to write data to a database dataTable.

Parameters

datasourceName – valid datasource name created in smarten.

tableName – table name.

mode – write mode. (Valid values are :0=Overwrite , 1=Append).

Returns

Returns true if write data to the database table successfully or false if failed to write data.  

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   ,

                     [“Alcoholic Drinks”,"Beer",4 , 787.45]   , 

                     [“Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["Emp_Id" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

ProductCategory   

ProductName  

Emp_Id

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4

dataTable.writeToDatabaseDataSource(“test_datasource” , "sales” , 0); write above dataTable to database table sales.


Boolean

removeDuplicateRows(String[] groupByColumns, String[] orderbycolumns, boolean removeFromTop)

Remove duplicate rows from the dataTable based on group by column.

Note : This method can throw an Exception when a failed to remove duplicates due to some error. This is useful for error reporting and to diagnose why failed to remove duplicates.

Parameters

groupByColumns  – specify a list of group by columns based on which duplicate rows will be removed. specify null to remove duplicate rows with all columns. 

orderbycolumns  – specify order by columns.

removeFromTop – true if starts removing from top false if starts removing from bottom.

Returns

Returns true if duplicate values are removed successfully or false if failed to remove duplicate.  

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   ,[“Alcoholic Drinks”,"Beer",4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,  [“Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

var distinctRowsDataTablet=DatasetUtil.removeDuplicateRows([“ProductCategory”,”SalesQty”] ,[” SalesPrice”],true); update dataTable as below.

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Confectionary

Mints

6

567.4

Alcoholic Drinks

Beer

4

787.45


Boolean

removeDuplicateColumns(String columnName)

Remove duplicate columns with a given column.

Note : This method can throw an Exception when a failed to remove duplicate column due to some error. This is useful for error reporting and to diagnose why failed to remove duplicate columns.

Parameters

columnName : column name for which need to remove duplicate columns.

Returns

Returns true if duplicate columns are removed successfully or false if failed to remove duplicate.  

Example

var arr=[[“Health Drinks”,"Strawberry",“Health Drinks”,2,45.67],[“Bakery”, "Cake", “Bakery”, 4 , 787]];    

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                         [["ProductType" , "STRING"]  ,["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

The dataTable will be as below.

ProductCategory   

ProductName  

ProductType   

SalesQty

SalesPrice

Health Drinks

Strawberry

Health Drinks

2

45.67

Bakery

Cake

Bakery

4

787.45

 DatasetUtil.removeDuplicateColumns(“ProductCategory”); removes duplicate column Producttype and updates the dataTable as below.

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Bakery

Cake

4

787.45


Boolean

updateColumnDataFromArray(String dataTableColumnName , Object[] columnData)

Update column data into dataTable.

Note : This method can throw an Exception when a failed to update column data due to some error. This is useful for error reporting and to diagnose why failed to update column data. If the column data is less than no rows the remaining column value is set to null.

Parameters

dataTableColumnName – dataTable column name.

columnData – array of column data objects.

Returns

Returns true if column data updated successfully or false if failed to update column data.  

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   ,[“Alcoholic Drinks”,"Beer",4 , 787.45]   , 

                      [“Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4

dataTable.updateColumnDataFromArray(“SalesQty” , [34 ,455  ]); update dataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

34

45.67

Alcoholic Drinks

Beer

455

787.45

Confectionary

Mints

NULL

567.4


Boolean

updateRowFromArray(int rowIndex , Object[] rowData)

Update row data into dataTable.

Note : This method can throw an Exception when a failed to update row data due to some error. This is useful for error reporting and to diagnose why failed to update row data.

Parameters

rowIndex – row index.

rowData – array of row data objects.

Returns

Returns true if row data updated successfully or false if failed to update row data. 

 Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   , [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,            [ “Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


dataTable.updateRowFromArray(2 , [“Alcoholic Drinks” ,”Whisky” , 57 , 890]);update dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Whisky

57

890

Confectionary

Mints

6

567.4


Boolean

updateCellValue(int rowIndex , String dataTableColumnName, Object value)

Update value at specific row and column in the dataTable.

Note : This method can throw an Exception when a failed to update cell value due to some error. This is useful for error reporting and to diagnose why failed to update cell value.

Parameters    

rowIndex – row index.

dataTableColumnName –dataTable column name.

rowData – array of row data objects.

Returns

Returns true if cell value updated successfully or false if failed to update cell value.  

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   , [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,            [ “Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.updateCellValue(2 , “SalesQty” ,  7); update  dataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

7

787.45

Confectionary

Mints

6

567.4


Boolean

addColumnFromArray(String dataTableColumnName , String type , Object[] data)

Create a new column with specified type and data in the dataTable.

Note : This method can throw an Exception when a failed to add column due to some error. This is useful for error reporting and to diagnose why failed to add a column. If the column data is less than no rows the remaining column value is set to null.

Parameters

dataTableColumnName – dataTable column name.

type – column data type

data – array of column data objects.

Returns

Returns true if column successfully or false if failed to add column. 

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   , [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,            [ “Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.addColumnFromArray(“ListPrice” ,  “DOUBLE” , [40.78 , 760.6 ,556]); update  dataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

ListPrice

Health Drinks

Strawberry

2

45.67

40.78

Alcoholic Drinks

Beer

4

787.45

760.6

Confectionary

Mints

6

567.4

556


Boolean

addColumnFromConstantValue(String dataTableColumnName , String type ,String value)

Create a new column with specified type and constant value in the dataTable.

Note : This method can throw an Exception when a failed to add column due to some error. This is useful for error reporting and to diagnose why failed to add column.

Parameters

dataTableColumnName – dataTable column name.

type – column type

value – constant data value.

Returns

Returns true if column successfully or false if failed to add column. 

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   , [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,            [ “Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.addColumnFromConstantValue(“BatchId” ,  “INT” , 2); update  dataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

BatchId

Health Drinks

Strawberry

2

45.67

2

Alcoholic Drinks

Beer

4

787.45

2

Confectionary

Mints

6

567.4

2


Boolean

addRowFromArray(Object[] rowData)

Add row data into the dataTable.

Note : This method can throw an Exception when a failed to add row due to some error. This is useful for error reporting and to diagnose why failed to add a row.

Parameters

rowData – array of row data objects.

Returns

Returns true if row data added successfully or false if failed to add row data.

  Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   , [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,            [ “Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.addRowFromArray([“Bakery” , “Cake” , 8 , 679]); update  dataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

8

679

 

DataTable

getDistinctRows(String[] columnNames)

Returns a dataTable with distinct rows for given column names.

Parameters

columnNames – array of columns for which distinct dataTable is returned.

Returns

Returns a dataTable with distinct rows for given column names.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Wine", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.getDistinctRows([“ProductCategory” , “ProductName” ]); returns  dataTable as below

ProductCategory   

ProductName  

Health Drinks

Strawberry

Alcoholic Drinks

Wine

Confectionary

Mints


DataTable

getSubDataTable(String[] columnNames)

Returns a dataTable with selecting specific columns from the current dataTable.


Parameters

columnNames – array of columns need to be selected from the dataTable.


Returns

Returns a dataTable with selecting specific columns from the current dataTable.


Example


var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Wine", 4 , 787.45]   , 

                     [“Confectionary”,"Mints", 6 , 567.4]];


var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


dataTable.getSubDataTable([ “ProductName” , “SalesPrice” ]); returns  dataTable as below

ProductName  

SalesPrice

Strawberry

45.67

Wine

787.45

Mints

567.4


DataTable

groupByAggregate(String[] groupByColumns , String[] measureColumns , Number[] measureOperations)

Aggregate dataTable based on group by columns.

Parameters

groupByColumns – array of group by columns.

measureColumns – array of measure columns.

measureOperations – array for measure operations .Valid values of array elements are 0=sum,1=Minimum,   2= Maximum, 3=First , 4=Last ,5=count , 6 = distinct count , 7 = Average , 8 = Standard deviation ,

9=Standard deviation population ,10=Variance ,11=Variance population ,12=Array,13=Distinct value array.

 Returns

Returns aggregated dataTable based on group by columns.

Example

var arr =[   [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Health Drinks” , "Chocolate",  4 , 75.67]   , [“Alcoholic Drinks”, "Beer", 4 , 787.45] ,[“Alcoholic Drinks”,"Wine",4,787.45] ,   

                    [“Alcoholic Drinks”,"Whisky" ,  7 , 867.45]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be a below

ProductCategory

ProductName

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Health Drinks

Chocolate

4

75.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Alcoholic Drinks

Whisky

7

867.45

dataTable.groupByAggregate([“ProductCategory”],[“ProductName”,”SalesQty”,“SalesPrice”],[12,0,7]) returns dataTable as below.

ProductCategory

ProductName

SalesQty

SalesPrice

Health Drinks

[“Strawberry” , “Chocolate”]

6

60.67

Alcoholic Drinks

[“Beer” , “Wine” , “Whisky”]

15

814.1167


DataTable

getTopNRecords(Number n , String[] orderByColumns , String[] sortOrders)

Returns dataTable with top n rows based on specified order.

Parameters

n – number of rows.

orderByColumns – specifies order by columns .

sortOrders – specifies sort orders for order by columns specified in argument2 . Valid values for elements are “asc” and “desc”.

Returns

Returns dataTable with top n rows based on specified order.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                      [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4

dataTable.getTopNRecords(2 , [“ProductName”] , [“asc”]);  returns dataTable as below.

ProductCategory

ProductName

SalesQty

SalesPrice

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4


Void

transformColumnNames()

Refactor all column names to remove invalid characters from column names. 


Note

If a column name contains characters except A-Z ,a-z,0-9 and underscore (_), then it replaces other characters with underscores.


Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,

                     [“Alcoholic Drinks”, "Beer", null , 787.45]   , 

                     [“Confectionary”,"Mints", 6 , 567.4]];


var schema = [["Product_Category" , "STRING"]  ,

                          ["Product Name" , "STRING"] ,

                          ["Sales@Qty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable.transformColumnNames() update dataTable as below.

Product_Category   

Product_Name  

Sales_Qty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

0

787.45

Confectionary

Mints

6

567.4


Number

getRecordCount(boolean excludeRowsWithMissingValues)

Returns no of rows in the dataTable.


Parameters

excludeRowsWithMissingValues - if true then ignore rows with null values.


Returns

Returns no of rows in the dataTable.


Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,

                     [“Alcoholic Drinks”, "Beer", null , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  null , 787.45]  ,   

                     [“Confectionary”,"Mints", 6 , 567.4]];


var schema = [["ProductCategory" , "STRING"]  ,

                          ["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

null

787.45

Alcoholic Drinks

Wine

null

787.45

Confectionary

Mints

6

567.4


dataTable.getRecordCount(true) returns 2.

Boolean

findReplaceColumnValues(String columnName,String findValue,String replaceWith,int  matchCriteria,boolean isIgnoreCase , boolean replaceEntireValue )

Replace specific value in given column name with new value.


Parameters

columnName – dataTable column name for which specified value will be replaced.

findValue – existing value in column need to be replaced.

replaceWith – value by which specified value will be replaced in the given column name.

matchCriteria – specify match type in column .1=equals,2=starts with , 3=ends with, 4=contains.

isIgnoreCase - if true, ignore case in match value.

replaceEntireValue – if true replace entire cell value otherwise replace only matched value.



Returns

true if value is replaced successfully , false otherwise.


Example


var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,

                     [“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Cool Drinks”,"Soda " ,  4 , 787.45]  ,   

                     [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Cool Drinks

Soda

4

787.45

Confectionary

Mints

6

567.4


dataTable.findAndReplace(“ProductCategory”, “Cool Drinks” , “Soft Drinks” ,1 ,false,true);  update dataTable as below.

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Whisky

4

787.45

Soft Drinks

Soda

4

787.45

Confectionary

Mints

6

567.4


dataTable.findAndReplace(“ProductCategory” , “Cool” , “Soft” ,2 , false,false);  update dataTable as below.

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Soft Drinks

Soda

4

787.45

Confectionary

Mints

6

567.4


dataTable.findAndReplace(“SalesQty” , 4 , 7 ,1 , false,true);  update dataTable as below.

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

7

787.45

Alcoholic Drinks

Wine

7

787.45

Confectionary

Mints

6

567.4


String[]

getUniqueDateFormats(String columnName)

Returns available date formats  from dataTablecolumns.

Parameters

columnName – dataTable column for which need to identify available dataformats.

Returns

Returns array for available date formats  in specified column.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , “12-08-2024 10:10“]   ,

                     [“Alcoholic Drinks”, "Beer", null , “23-08-2022 10:20”]   , 

                     [“Alcoholic Drinks”,"Wine " ,  null , “2022-07-17 08:30”]  ,   

                     [“Confectionary”,"Mints", 6 , “2023-08-19 10:30”]];

var schema = [["ProductCategory" , "STRING"] ,  ["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["Date" , "STRING"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable.getUniqueDateFormats (“Date”); returns array [“dd-MM-yyyy HH:mm” , “yyyy-MM-dd” ]

DataTable

split(String columnName,int splitBy,boolean isSplitFromRight,String splitValue,String newColumnName1,String newColumnName2 )

Split specified column based on given options.

Parameters

columnName – dataTable column name for which column will be split.

splitBy – specify split type in column .0=string ,1=regex , 2=length.

isSplitFromRight – if splits column from right else splits from left.

splitValue – specifies split value based on argument “splitBy”. For example if splitBy=0 then separator value is passed , splitBy=1 then regex pattern is passed and splitBy=2 then length value is passed to splitValue.

newColumnName1 - new column name after split if newColumnName1 is null or empty its add column columnName with _1.

newColumnName2 - new column name after split if newColumnName2 is null or empty its add column columnName with _2.

Returns

Returns a dataTable with a splitting specified column.

Example

var arr =[[“Health Drinks” , "3-6",”E-230”,“Vuong Smith”] ,[“Alcoholic Drinks”,"6-10",”E-80”,“Heather Bruce”]   ,   [“Confectionary”,"2 14” ,”E-34”,“Jason V Mehata]];

var schema = [["ProductCategory" , "STRING"]  , ["Range" , "STRING"] ,

                          ["EmpId" , "STRING"]];["EmployeeName" , "STRING"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema); dataTable will be as below


ProductCategory   

Range

EmpId

EmployeeName

Health Drinks

3-6

E-230

Vuong Smith

Alcoholic Drinks

6-10

E-80

Heather Bruce

Confectionary

12 20

E-34

Jason Vmehata

 

dataTable.split(“EmployeeName”,0,false,” “); returns dataTable as below

ProductCategory   

Range

EmpId

EmployeeName

EmployeeName_1

EmployeeName_2

Health Drinks

3-6

E-230

Vuong Smith

Vuong

Smith

Alcoholic Drinks

6-10

E-80

Heather Bruce

Heather

Bruce

Confectionary

12 20

E-34

Jason Vmehata

Jason

Vmehata

 dataTable.split(“Range”,1,false,”\D”); returns dataTable as below

ProductCategory   

Range

Range_1

Range_2

EmpId

EmployeeName

Health Drinks

3-6

3

6

E-230

Vuong Smith

Alcoholic Drinks

6,10

6

10

E-80

Heather Bruce

Confectionary

12 20

12

20

E-34

Jason Vmehata

 dataTable.split(“EmpId”,2,false,”2”); returns dataTable as below.

ProductCategory   

Range

EmpId

EmpId_1

EmpId_2

EmployeeName

Health Drinks

3-6

E230

E-

230

Vuong Smith

Alcoholic Drinks

6-10

E80

E-

80

Heather Bruce

Confectionary

12 20

E34

E-

34

Jason Vmehata


Number

sum(String columnName)

Returns sum of all values for specified column name in dataTable.

Parameters

columnName – measure column name for which sum is to be returned.

Returns

Returns sum of all values for specified column name in dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

var dataTable= DatasetUtil.createDataTableFromArray (arr , schema);

dataTable.sum(“SalesQty”); returns 16.


Number

minimum(String columnName)

Returns min value from all values for specified column name in the dataTable.

Parameters

columnName – measure column name for which min is to be returned.

Returns

Returns min value from all values for specified column name in the dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.minimum(“SalesQty”); returns 2.

Number

maximum(String columnName)

Returns max value from all values for specified column name in dataTable.

Parameters

dataTable– dataTable object.

columnName – measure column name for which max is to be returned.

Returns

Returns max value from all values for specified column name in dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.maximum(“SalesQty”); returns 6.


Number

count(String columnName)

Returns count of  values for specified column names in the dataTable.

Parameters

columnName – measure column name for which count is to be returned.

Returns

Returns count of  values for specified column names in the dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  null , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

NULL

787.45

Confectionary

Mints

6

567.4

dataTable.count(“SalesQty”); returns 3.


Number

mean( String columnName)

Returns average of all values for specified column name in dataTable.

Parameters

columnName – measure column name for which mean is to be returned.

Returns

Returns average of  all values for specified column name in dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.mean(“SalesPrice”); returns 546.9925.



Number

median(String columnName)

Returns median of all values for specified column name in dataTable.

Parameters

columnName – measure column name for which median is to be returned.

Returns

Returns median of  all values for specified column name in dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.median(“SalesPrice”); returns 567.

Number

kurtosis( String columnName)

Returns measure of the peakedness for specified column name in the dataTable.

Parameters

columnName – measure column name for which kurtosis is to be returned.

Returns

Returns measure of the peakedness for specified column name in the dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.kurtosis(“SalesQty”); returns -1.

dataTable.kurtosis(“SalesPrice”); returns -0.93.


Number

skewness(String columnName)

Returns skewness of all values for specified column name in the dataTable.

Parameters

columnName – measure column name for which skewness is to be returned.

Returns

Returns skewness of  all values for specified column name in the dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];


var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.skewness(“SalesPrice”); returns -0.88.

Number

standardDeviation( String columnName)

Returns standard deviation of all values for specified column name in dataTable.

Parameters

columnName – measure column name for which standard deviation is to be returned.

Returns

Returns standard deviation of  all values for specified column name in dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];


var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.standardDeviation(“SalesQty”); returns 1.63.

dataTable.standardDeviation(“SalesPrice”); returns 349.94.

Number

mode( String columnName)

Returns mode of all values for specified column name in dataTable.

Parameters

columnName – measure column name for which mode is to be returned.

Returns

Returns mode of all values for specified column name in dataTable.


var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];


var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];


var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4


dataTable.mode(“SalesQty”) returns 4.

DataTable

getOutliers(String[] columnNames )

Returns outliers values for specified column names in the dataTable.

Parameters

columnName – measure column name for which sum is to be returned.

Returns

Returns outliers values for specified column names in the dataTable.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7]];

                     [“Snacks”, “Macaroni” , 456,569.8] , [“Tea” , “Ginger Tea”,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7

 

dataTable.getOutliers([“SalesQty”]); returns dataTable as  below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7



Boolean

removeOutliers(String[] columnNames )

Remove outliers for specified columns.

Parameters

columnName – measure column name for which you want to remove.

Returns

Returns true if outliers are removed successfully.  Returns false if failed to remove the outliers.  

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7],

                     [“Snacks”, “Macaroni” , 456,569.8] , [“Tea” , “Ginger Tea”,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7


dataTable.removeOutliers([“SalesQty”]) updates dataset as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7



Boolean

replaceOutliers(String columnName,  Object replaceValue)

Replace outliers for specific columns using replace value.

Parameters

columnName – measure column name for which you want to replace outliers.

replaceValue - value which you want to replace in outliers value.

Returns

Returns true if outliers are replaced successfully.  Returns false if failed to replace the outliers.  

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7],

                     [“Snacks”, “Macaroni” , 456,569.8] , [“Tea” , “Ginger Tea”,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7


dataTable.replaceOutliers(“SalesQty”,0) update dataset as  below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

0

569.8

Tea

Ginger Tea

0

609.7



Boolean

addColumnWithSeries(String newColumnName , Number seriesStartValue, Number seriesEndValue,Number  seriesIncrementNumber)

Add new column using specified series and increment number after the end value is set null. 

Create a new column with specified type and data in the dataTable.

Note : This method can throw an Exception when a failed to add column due to some error. This is useful for error reporting and to diagnose why failed to add column.

Parameters

newColumnName – new column name.

seriesStartValue– series start from.

seriesEndValue– series end.

seriesIncrementNumber- series increment.

Returns

Returns true if column successfully or false if failed to add column. 

Example

var arr =[    [“Health Drinks” , "Strawberry",2 , 45.67]   , [“Alcoholic Drinks”,"Wine ",4 , 787.45]  ,            [ “Confectionary”,"Mints",6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,["SalesQty" , "INT"],   

                          ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

dataTable.addColumnWithSeries (“RowNo” , 1,3,1); update  dataTable as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

RowNo

Health Drinks

Strawberry

2

45.67

1

Alcoholic Drinks

Beer

4

787.45

2

Confectionary

Mints

6

567.4

3



DataTable

getSampleData(Number samplingType, Number sampleDataSize , boolean percentOrAbsolute, String columnName)

get sample data from the dataTable based on specified options and return dataTable for this data.

Parameters

samplingType - specifies sampling method type . Valid values are 1=Simple random sampling , 2=Stratified sampling ,3=Systematic sampling, 4=Top , 5=Bottom.

sampleDataSize  - specifies size for sampling.

percentOrAbsolute - if the true sampling size specified in argument2 is considered as % of records ,else it’s considered as no of records.

columnName - specifies column name for Stratified sampling.

Returns

Returns dataTable with sample records.

Example

 var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7]];

                     [“Snacks”, “Macaroni” , 4,569.8] , [“Tea” , “Ginger Tea”,3,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

4

569.8

Tea

Ginger Tea

3

609.7

dataTable.getSampleData(3, 50 , true,"ProductCategory"); returns dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Confectionary

Mints

6

567.4

Snacks

Macaroni

4

569.8

Bakery

Cookies

7

609.7

Alcoholic Drinks

Wine

4

787.45

dataTable.getSampleData(3, 5 , false,"ProductCategory");  returns dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Confectionary

Mints

6

567.4

Snacks

Macaroni

4

569.8

Bakery

Cookies

7

609.7

Alcoholic Drinks

Wine

4

787.45




Boolean

removeColumns(String[] columnNames)

Remove specific columns.

Parameters

columnNames – column name for which you want to remove.

Returns

Returns true if columns are removed successfully.  Returns false if failed to remove the columns.  

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7]];

                     [“Snacks”, “Macaroni” , 456,569.8] , [“Tea” , “Ginger Tea”,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7


dataTable.removeColumns(“SalesQty”);


dataTable will be as below

ProductCategory   

ProductName  

SalesPrice

Health Drinks

Strawberry

45.67

Alcoholic Drinks

Beer

787.45

Alcoholic Drinks

Wine

787.45

Confectionary

Mints

567.4

Bakery

Cake

569.8

Bakery

Cookies

609.7

Snacks

Macaroni

569.8

Tea

Ginger Tea

609.7



Boolean

removeColumsWithAllNull()

Remove columns with all null values.

Returns

Returns true if columns are removed successfully.  Returns false if failed to remove the columns.  

Example

var arr =[    [“Health Drinks” , "Strawberry",  null , 45.67]   ,[“Alcoholic Drinks”, "Beer", null , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  null , 787.45]  ,   [“Confectionary”,"Mints", null , 567.4]

                     [“Bakery”, “Cake” , null,569.8] , [“Bakery” , “Cookies”,null,609.7]];

                     [“Snacks”, “Macaroni” ,null, 456,569.8] , [“Tea” , “Ginger Tea”,null,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

Null

45.67

Alcoholic Drinks

Beer

Null

787.45

Alcoholic Drinks

Wine

Null

787.45

Confectionary

Mints

Null

567.4

Bakery

Cake

Null

569.8

Bakery

Cookies

Null

609.7

Snacks

Macaroni

Null

569.8

Tea

Ginger Tea

Null

609.7


dataTable.removeColumsWithAllNull();


dataTable will be as below

ProductCategory   

ProductName  

SalesPrice

Health Drinks

Strawberry

45.67

Alcoholic Drinks

Beer

787.45

Alcoholic Drinks

Wine

787.45

Confectionary

Mints

567.4

Bakery

Cake

569.8

Bakery

Cookies

609.7

Snacks

Macaroni

569.8

Tea

Ginger Tea

609.7



Boolean

removeRowsWithAllNull()

remove all null rows from dataTable

Returns

Returns true if null rows are removed successfully ,false otherwise.

Example

var arr =[    [“Health Drinks” , "Strawberry",  null , 45.67]   ,[“Alcoholic Drinks”, "Beer", null , 787.45]   , 

                     [null , null ,  null , null]  ,   [“Confectionary”,"Mints", null , 567.4]

                     [“Bakery”, “Cake” , null,569.8] , [“Bakery” , “Cookies”,null,609.7]];

                     [null,  null ,null,null] , [“Tea” , “Ginger Tea”,null,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

Null

45.67

Alcoholic Drinks

Beer

Null

787.45

null

null

null

null

Confectionary

Mints

Null

567.4

Bakery

Cake

Null

569.8

Bakery

Cookies

Null

609.7

null

null

null

null

Tea

Ginger Tea

Null

609.7


dataTable.removeRowsWithAllNull(); updates dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

Null

45.67

Alcoholic Drinks

Beer

Null

787.45

Confectionary

Mints

Null

567.4

Bakery

Cake

Null

569.8

Bakery

Cookies

Null

609.7

Tea

Ginger Tea

Null

609.7



Boolean

removeRowsForThisColumnValues(String columnName , Object[] columnValues)

Removes all rows for  value for specified column name is in given list.

 Parameters

columnName  - column name for which values are to be checked.

columnValues - values for column for which rows needs to be removed.

Returns

Returns true if rows with column values are removed successfully ,false otherwise.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7]];

                     [“Snacks”, “Macaroni” , 456,569.8] , [“Tea” , “Ginger Tea”,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7


dataTable.removeRowsForThisColumnValues(ProductCategory  , [“Bakery” , “Alcoholic Drinks”])

updates dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Confectionary

Mints

6

567.4

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7


Boolean

sortDataTable( String[] columnNames , String[] sortOrders)

sort dataTable based on specified columns and sort orders.

Parameters

columnNames  - name of columns need to sort

 sortOrders - sort orders of each column specified in argument1. Valid values are asc and desc.

Returns

Returns true if the dataTable is sorted for specified options.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7]];

                     [“Snacks”, “Macaroni” , 456,569.8] , [“Tea” , “Ginger Tea”,320,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Wine

4

787.45

Alcoholic Drinks

Beer

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

456

569.8

Tea

Ginger Tea

320

609.7

var columnNames = ["ProductCategory","ProductName"];

var sortOrders= ["desc","asc"];

dataTable.sortDataTable(columnNames  , sortOrders);


dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Tea

Ginger Tea

320

609.7

Snacks

Macaroni

456

569.8

Health Drinks

Strawberry

2

45.67

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Beer

4

787.45




Boolean

addBucketColumn(String newColumnName ,  String targetColumnName ,Number bucketTechinque , Number noOfBuckets , Number[][] customBucketRange)

Parameters

newColumnName  - new column name

targetColumnName - specifies column name for which buckets needs to create.

bucketTechinque  - specifies bucket type . Valid values are 0=Simple (Symmetric range buckets),1=Quartile (Evenly distributed range buckets) , 2=Custom.

noOfBuckets  - specifies no of buckets to generate.

customBucketRange - if bucketTechinque specified in argument2 is custom type then values specifies range of buckets.

Returns

Returns true if bucket column created successfully , false if failed to create bucket column.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7]];

                     [“Snacks”, “Macaroni” , 7,569.8] , [“Tea” , “Ginger Tea”,9,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

7

569.8

Tea

Ginger Tea

9

609.7

var bucket = [[1,3]  ,[4,6] ,

                          [7,9],   [10,11]];

dataTable.addBucketColumn("Buckets" , "SalesQty" , 2,3 , bucket); updates dataTable as below


ProductCategory   

ProductName  

SalesQty

Buckets

SalesPrice

Health Drinks

Strawberry

2

1-3

45.67

Alcoholic Drinks

Beer

4

4-6

787.45

Alcoholic Drinks

Wine

4

4-6

787.45

Confectionary

Mints

6

4-6

567.4

Bakery

Cake

3

1-3

569.8

Bakery

Cookies

7

7-9

609.7

Snacks

Macaroni

7

7-9

569.8

Tea

Ginger Tea

9

7-9

609.7



Boolean

addColumnWithDataOperation(String newColumnName , String targetColumnName , Number dataOperation , String[] groupByColumns , String[] orderByColumns,String[] sortOrders)

adds a new column for data operation for specified options.

Parameters

newColumnName  - new column name

targetColumnName - specified column name in which data operations need to apply.

dataOperation  - specifies data operation type . Valid values are 1=Sum,2=Average,3=Effective Average,4=Count,5=Max,6=Min,7=First,8=Last,9=Row Percentage,10=Relative Row Difference,11=Relative Row Difference Percentage,12=Cumulative Sum,13=Effective Count,14=Rank,15=Percent Rank,16=Dense Rank,17=Array,18=Dist Array,19=Dist Count.

groupByColumns  - specifies group by columns.

orderBycolumns -  specified order by columns.

sortOrders - specifies sort orders for order by columns specified in argument2 . Valid values for elements are “asc” and “desc”.

Returns

Returns true if bucket column created successfully , false if failed to create bucket column.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  4 , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4],

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,7,609.7],

                     [“Snacks”, “Macaroni” , 7,569.8] , [“Tea” , “Ginger Tea”,10,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

4

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

7

609.7

Snacks

Macaroni

4

569.8

Tea

Ginger Tea

3

609.7

dataTable.addColumnWithDataOperation(“Sum_SalesQty” , “SalesQty” , 19 ,[“ProductCategory “],null,null); updates dataTable as below


ProductCategory   

ProductName  

SalesQty

Sum_SalesQty

SalesPrice

Alcoholic Drinks

Beer

4

8

787.45

Alcoholic Drinks

Wine

4

8

787.45

Bakery

Cake

3

10

569.8

Bakery

Cookies

7

10

609.7

Confectionary

Mints

6

6

567.4

Health Drinks

Strawberry

2

2

45.67

Snacks

Macaroni

4

4

569.8

Tea

Ginger Tea

3

3

609.7


dataTable.addColumnWithDataOperation(“temp” , “SalesQty” , 1 ,[“ProductCategory “],[“SalesPrice”],”asc”) updates dataTable as below


ProductCategory   

ProductName  

SalesQty

temp

SalesPrice

Alcoholic Drinks

Beer

4

1

787.45

Alcoholic Drinks

Wine

4

1

787.45

Bakery

Cake

3

2

569.8

Bakery

Cookies

7

2

609.7

Confectionary

Mints

6

1

567.4

Health Drinks

Strawberry

2

1

45.67

Snacks

Macaroni

4

1

569.8

Tea

Ginger Tea

3

1

609.7


Boolean

fillDataInColumn(String columnName ,Number fillCriteria ,  Object valueForCustomCriteria)

fill empty values in the given column name based on specified options.

Parameters

columnName  - column name in which you need to fill empty values.

fillCriteria  - specifies fill criteria. Valid values are 0=value,1=Previous,2=Min,3=Median,4=Mean,5=Max

valueForCustomCriteria - specified values to fill empty data if argument2 is specified as value.

Returns

Returns true if the empty value is filled successfully.

Example

var arr =[ [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  null , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]

                     [“Bakery”, “Cake” , 3,569.8] , [“Bakery” , “Cookies”,null,609.7]];

                     [“Snacks”, “Macaroni” , 7,569.8] , [“Tea” , “Ginger Tea”,10,609.7]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below

ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

null

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

null

609.7

Snacks

Macaroni

7

569.8

Tea

Ginger Tea

10

609.7

dataTable.fillDataInColumn( “SalesQty” , 5 ,null); updates dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

10

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

10

609.7

Snacks

Macaroni

4

569.8

Tea

Ginger Tea

3

609.7


dataTable.fillDataInColumn( “SalesQty” , 0 ,111); updates dataTable as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

111

787.45

Confectionary

Mints

6

567.4

Bakery

Cake

3

569.8

Bakery

Cookies

111

609.7

Snacks

Macaroni

4

569.8

Tea

Ginger Tea

3

609.7



Boolean

splitToRow(String sourceColumnName , String separator , String newColumnName)

split rows for  specified column name by separator.

Parameters

sourceColumnName - column name for which we need to split rows.

separator - separator by which column value will be splitted.

newColumnName - new column name created after splitted value.

Returns

Returns true if a new column is created successfully by splitting column value.

Example

var arr =[  [“Alcoholic Drinks”, "Wine", 4 , 787.45]   , 

                     [“Bakery”, “Cake” , 3,569.8] ];

var schema = [["ProductCategory" , "STRING"]  ,["Products" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

the dataTable will be as below.


ProductCategory   

Products

SalesQty

SalesPrice

Alcoholic Drinks

Wine,Beer

4

787.45

Bakery

Cake,Cookies

3

569.8

dataTable.splitToRow(“Products” , “,” , “ProductName”);  updates dataTable as below.


ProductCategory   

Products

ProductName

SalesQty

SalesPrice

Alcoholic Drinks

Wine,Beer

Wine

4

787.45

Alcoholic Drinks

Wine,Beer

Beer

4

787.45

Bakery

Cake,Cookies

Cake

3

569.8

Bakery

Cake,Cookies

Cookies

3

569.8


Boolean

mergeColumns(String[] columnNames , String separator , String newColumnName)

merge specified columns using a separator and create a new column.

Parameters

columnNames - column names to be merge.

separator - separator by which values from specified columns will be merged.

newColumnName - new column name needs to be created.

Returns

Returns true if the column merged successfully , false otherwise.

Example

var arr =[    [“Health Drinks” , "Strawberry",  2 , 45.67]   ,[“Alcoholic Drinks”, "Beer", 4 , 787.45]   , 

                     [“Alcoholic Drinks”,"Wine " ,  null , 787.45]  ,   [“Confectionary”,"Mints", 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["ProductName" , "STRING"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);

dataTable will be as below


ProductCategory   

ProductName  

SalesQty

SalesPrice

Health Drinks

Strawberry

2

45.67

Alcoholic Drinks

Beer

4

787.45

Alcoholic Drinks

Wine

null

787.45

Confectionary

Mints

6

567.4


dataTable.mergeColumns([“ProductCategory ” , “ProductName”] , “-” , “Product”);  returns dataTable as below


ProductCategory   

ProductName  

Product

SalesQty

SalesPrice

Health Drinks

Strawberry

Health Drinks-Strawberry

2

45.67

Alcoholic Drinks

Beer

Alcoholic Drinks-Beer

4

787.45

Alcoholic Drinks

Wine

Alcoholic Drinks-Wine

null

787.45

Confectionary

Mints

Confectionary-Mints

6

567.4


DataTable

filterDataTable(String filterCriteriaJson)

filter using specified criteria and filter datatable

filterCriteriaJson - criteria for filter datatable

Logical operators -  And , Or

Operator - 

String type (=, !=, Null, Not Null, Starts with, Ends with, Contains, Does not start with, Does not end with, Does not contain)

Number type (=, <, >, <=, >=, !=, Null, Not Null, Between, Not between)

Date type (=, Before, After, !=, Null, Not Null, Between, Not Between)

Date Format - dd-MM-yyyy hh:mm


Returns

Returns datatable after filter.

Example

var arr =[  ["Health Drinks" ,  DateUtil.stringToDate("15-04-2018", "dd-MM-yyyy"),  2 , 45.67]   ,["Alcoholic Drinks",DateUtil.stringToDate("16-04-2018", "dd-MM-yyyy"), 4 , 787.45], 

                     ["Alcoholic Drinks",DateUtil.stringToDate("17-04-2018", "dd-MM-yyyy") ,  4, 787.45]  ,   ["Confectionary",DateUtil.stringToDate("18-04-2018", "dd-MM-yyyy"), 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["Date" , "TIMESTAMP"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below


ProductCategory   

Date 

SalesQty

SalesPrice

Health Drinks

15-04-2018

2

45.67

Alcoholic Drinks

16-04-2018

4

787.45

Alcoholic Drinks

17-04-2018

4

787.45

Confectionary

18-04-2018

6

567.4


var filterCriteriaJson =[{Col:'ProductCategory',Op : '=',Val:'Alcoholic Drinks',Logical : 'And'},{Col:'Date',Op : 'Between',Val:'15-04-2018#||#17-04-2018',Logical : 'And'}];

 filterCriteriaJson = JSON.stringify(filterCriteriaJson);

dataTable.filterDataTable(filterCriteriaJson); returns dataTable as below


ProductCategory   

Date  

SalesQty

SalesPrice

Alcoholic Drinks

16-04-2018

4

787.45

Alcoholic Drinks

17-04-2018

4

787.45



Boolean

addColumnFromDate(String dateColumnName  ,String  newColumnName ,Number  columnType , boolean isFY)

extract column and add column using dateColumn.

dateColumnName - data table date column name

newColumnName -  new column name.

columnType - type for column which we want to extract.(Valid values are 0=YEAR , 1=QUARTER , 2=MONTH , 3=WEEK_OF_YEAR, 4=WEEK_OF_MONTH , 5=DAY_OF_MONTH , 6=HOUR , 7=MINUTE, 8=SECOND)

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial year.

Returns

Returns true if the column was added successfully , false otherwise.


Example

var arr =[  ["Health Drinks" ,  DateUtil.stringToDate("15-04-2018 11:12:13", "dd-MM-yyyy hh:mm:ss"),  2 , 45.67]   ,["Alcoholic Drinks",DateUtil.stringToDate("16-04-2018 11:12:13", "dd-MM-yyyy hh:mm:ss"), 4 , 787.45],  ["Alcoholic Drinks",DateUtil.stringToDate("17-04-2019 11:12:13", "dd-MM-yyyy hh:mm:ss") ,  4, 787.45]  ,   ["Confectionary",DateUtil.stringToDate("18-04-2019 11:12:13", "dd-MM-yyyy hh:mm:ss"), 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["Date" , "TIMESTAMP"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below


ProductCategory   

Date 

SalesQty

SalesPrice

Health Drinks

15-04-2018

2

45.67

Alcoholic Drinks

16-04-2018

4

787.45

Alcoholic Drinks

17-04-2019

4

787.45

Confectionary

18-04-2019

6

567.4


dataTable.addColumnFromDate("Date"  ,"Year" ,0 ,false); returns dataTable as below


ProductCategory   

Date 

SalesQty

SalesPrice

Year

Health Drinks

15-04-2018

2

45.67

2018

Alcoholic Drinks

16-04-2018

4

787.45

2018

Alcoholic Drinks

17-04-2019

4

787.45

2019

Confectionary

18-04-2019

6

567.4

2019



Boolean

validateSchema(String[][] validateSchema)

return true if schema is validate with current datatable.

validateSchema – column schema

Returns

Returns true if the column schema match successfully , false otherwise.

Returns

Returns true if the column was added successfully , false otherwise.


Example

var arr =[  ["Health Drinks" ,  DateUtil.stringToDate("15-04-2018 11:12:13", "dd-MM-yyyy hh:mm:ss"),  2 , 45.67]   ,["Alcoholic Drinks",DateUtil.stringToDate("16-04-2018 11:12:13", "dd-MM-yyyy hh:mm:ss"), 4 , 787.45],  ["Alcoholic Drinks",DateUtil.stringToDate("17-04-2019 11:12:13", "dd-MM-yyyy hh:mm:ss") ,  4, 787.45]  ,   ["Confectionary",DateUtil.stringToDate("18-04-2019 11:12:13", "dd-MM-yyyy hh:mm:ss"), 6 , 567.4]];

var schema = [["ProductCategory" , "STRING"]  ,["Date" , "TIMESTAMP"] ,

                          ["SalesQty" , "INT"],   ["SalesPrice" , "DOUBLE"]];

var dataTable= DatasetUtil.createDataTableFromArray(arr , schema);


dataTable will be as below


ProductCategory   

Date 

SalesQty

SalesPrice

Health Drinks

15-04-2018

2

45.67

Alcoholic Drinks

16-04-2018

4

787.45

Alcoholic Drinks

17-04-2019

4

787.45

Confectionary

18-04-2019

6

567.4


var validateSchema = [["ProductCategory" , "STRING"]  , ["Date" , "TIMESTAMP"] , ["SalesQty" , "INT"], ["SalesPrice" , "DOUBLE"]];

dataTable.validateSchema(validateSchema ); return true if validate successfully, false otherwise.





DatabaseUtil functions

Return type

Method description

Boolean

executeInsertQueryToDatabase (String datasourceName , String insertQuery)

execute insert query in database.

Note : This method can throw an Exception when a failed to execute insert query due to some error. This is useful for error reporting and to diagnose why failed to execute insert query.

Parameters

datasourceName – datasource name.

insertQuery – database query.

Return

Returns true if insert query executed successfully or false if failed execute insert query.  

Example

DatabaseUtil.insertQueryToDatabase(“test_datasource” , “INSERT INTO sales_records VALUES(‘Snacks’ , ‘Macaroni’ , 148 , 3311 , 52.84, 56.89) ”);

Boolean

executeUpdateQueryToDatabase(String datasourceName , String updateQuery)

execute update query in database.

Note : This method can throw an Exception when a failed to execute update query due to some error. This is useful for error reporting and to diagnose why failed to execute update query.

Parameters

datasourceName – datasource name.

updateQuery – database query.

Return

Returns true if update query executed successfully or false if failed execute update query.  

Example

DatabaseUtil.updateQueryToDatabase(“test_datasource” , “UPDATE sales_records set SalesQty = 0 where SalesQty IS NULL ”);

Boolean

executeDeleteQueryToDatabase(String datasourceName , String deleteQuery)

execute delete query in database.

Note : This method can throw an Exception when a failed to execute delete query due to some error. This is useful for error reporting and to diagnose why failed to execute delete query.

Parameters

datasourceName – datasource name.

deleteQuery – database query.

Return

Returns true if delete query executed successfully or false if failed execute delete query.  

Example

DatabaseUtil.deleteQueryToDatabase(“tbl_datasource”,“DELETE FROM sales_tbl where date < ‘2012-12-25’ ”);



APIUtil functions

Return type

Method description

String

callAPI(String url, String method, String headers, String requestParameters)

Call api with specified url with given method ,headers and param and return string response.

Parameters

url – domain url.

method – request method.(Valid values are GET , PUT , POST , HEAD , DELETE , CONNECT , OPTION , DELETE , TRACE).

headers – request headers.

requestParameters – request parameters.

Return

Returns string response coming from url call.

Example

APIUtil.callAPI(‘http://localhost:8080/test” , “POST” , "{\"Content-Type\":\"application/json\";\"Accept\":\"application/json\"}" ,"{\"name\":\"my_username\",\"email\":\"user@example.test\",\"password\":{\"value\":\"my_password\"} }");



String function

Return type

Method description

Number

indexOf(String stringToken)

Find index of specified string.Character index starts with 0.

Parameters

stringToken – string for which we need to find an index.

Return

Returns index of specified stringToken if match otherwise return -1.

Example

“JavaScript”. indexOf(“Script”); returns 4.

“JavaScript”. indexOf(“script”); returns -1.

String 

substring(int start , int end)

Returns substring based on start and end index.Character index starts with 0.

Parameters

start – start index in string.

end – end index in string

Return

Returns substring based on start and end index.

Example

“JavaScript”.substring(4,10); returns “Script”.

String

toUpperCase()

Converts a string to uppercase.

Return

Returns an upper case string.

Example

“JavaScript”.toUpperCase(); returns “JAVASCRIPT”.

String

toLowerCase()

Converts a string to lowercase.

Return

Returns a lower case string.

Example

“JavaScript”.toLowerCase(); returns “javascript”.

String

replace(String targetToken, String replacementToken)

Replace first occurrence of specified string with new string.

Parameters

targetToken – string to be replaced.

replacementToken – string by which stringToken will replace.

Return

Returns a string by replacing the first occurrence of specified string with new string.

Example

“JavaScript”. replace(“a” , “”); returns “JvaScript”.

String

replaceAll(String targetToken, String replacementToken)

Replace all occurrences of specified string with new string.

Parameters

targetToken – string to be replaced.

replacementToken – string by which stringToken will replace.

Return

Returns a string by replacing all occurrences of specified string with new string.

Example

“JavaScript”. replace(“a” , “”); returns “JvScript”.

String

charAt(int index)

Returns char value at specified index.Character index starts with 0.

Parameters

index – string index.

Return

Returns char value at specified index.

Example

“JavaScript”.charAt(5); returns ‘c’.

Number

charCodeAt(int index)

Returns ascii value of char  at specified index.Character index starts with 0.

Parameters

index – string index.

Return

Returns char value at specified index.

Example

“JavaScript”.charAt(5); returns 67.

boolean

startsWith(String otherString)

Returns true if string is starting with specified string , false otherwise.

Parameters

otherString – other string to check for starts with.

Return

Returns true if string is starting with specified string , false otherwise.

Example

“JavaScript”.startsWith (“Java”); returns true.

boolean

endsWith(String otherString)

Returns true if string is ending with specified string , false otherwise.

Parameters

otherString – other string to check for ends with.

Return

Returns true if string is ending with specified string , false otherwise.

Example

“JavaScript”.endsWith(“Script”) returns true.

String

concat(String otherString)

Concat specifies string to current string and returns it.

Parameters

otherString – string to concat.

Return

Returns string concatenate specified string to current string.

Example

“Java”. concat(“Script”); returns “JavaScript”.

String[]

split(String separator)

Splits a string into an array.

Parameters

separator – Specifies separator to use when splitting the string.

Returns

The array of strings computed by splitting  string.

Example

“Java,JavaScript”.split(“,”);  returns array [“Java” , “JavaScript”].

String

reverse()

Reverse a string

Example

“java”.reverse(); return “avaj”.



StringUtil functions


Return type

Method description


String

extractStringFromLeft(String sourceString , Number noOfChar)

Returns a specified number of characters from a string starting with the first character

Parameters

sourceString - The text from which the partial words are to be returned.

noOfChar - The number of characters to be extracted from the beginning of the text.

Returns

Returns a specified number of characters from a string starting with the first character

Example

StringUtil.extractStringFromLeft(“testscript”,2); return “te”

String

extractStringFromRight(String sourceString , Number noOfChar)

Returns the specified number of characters from the end of a specified string

Parameters

sourceString - The text from which the specified number of characters should be returned from the end.

noOfChar - The number of characters to be returned from the string.

Returns

Returns the specified number of characters from the end of a specified string

Example

StringUtil.extractStringFromRight(“testscript”,2); return “pt”


String

concatValues(Object[] values, String delimiter)

Combine all string from array with delimiter and return it.

Parameters

values - The text that has to be concatenated with argument 2.

delimiter- The text that has to be concatenated with argument 1.

Returns

String  concat value array.

Example 

var value =[[“test”],[“script”]];

StringUtil.concatValues(value,”,”); return “test,script”

String

formatNumber(Number value , String format)

A string containing value formatted as defined by format_string.

Parameters

value - value for format

format - value formatter. Valid values are “General number” , “Currency” , “Fixed” , “Standard” , “Percent” , “Scientific”.

Returns

String after formatting.

Example

StringUtil.formatNumber(12345.67 , “General number”) returns 12345.67.

StringUtil.formatNumber(12345.67 , “Currency”) returns $12,345.67.

StringUtil.formatNumber(12345.67 , “Fixed”) returns 12345.67.

StringUtil.formatNumber(12345.67 , “Standard”) returns 12,345.67.

StringUtil.formatNumber(12345.67 , “Percent”) returns 1,234,567.00%.

StringUtil.formatNumber(12345.67 , “Scientific”) returns 1.23E4.


String

lpad(String sourceString , Number lengthOfResultString , String paddingString)

Returns a string with left-pad of specified length

Parameters

sourceString - The text in which left-pad is to be added

lengthOfResultString - The length of string to be returned

paddingString - The text which is to be padded in specified string

Returns

Returns a string with left-pad of specified length

Example

StringUtil.lpad(“test”,10,”abc”); return “abcabctest” 

String

rpad(String sourceString , Number lengthOfResultString , String paddingString)

Returns a string with right-pad of specified length

Parameters

sourceString - The text in which right-pad is to be added

lengthOfResultString - The length of string to be returned

paddingString -The text which is to be padded in specified string

Returns

The array of strings computed by splitting  string.

Example

StringUtil.rpad(“test”,10,”abc”); return “testabcabc” 







DateUtil functions

Note: 

  1. “Date” object referred in this help document represent date and time values in single object.

  2. Financial year  is as per Financial Year start month set by admin in Smarten.



Return type

Method description


Date

getCurrentDate()

Returns current system date and time.


Example

DateUtil.getCurrentDate();

Date

addIntervalToDate(Date date, String intervalType, int noOfIntervals)

Adds a certain date and time intervals in a given date object and returns a new date.


Parameters

date – Date object in which intervals need to be added.

intervalType – Specify the type of interval which needs to be added in parameter 1 date object. Valid values are: d=Days, w=Weeks, h=Hours, n=Minutes, s=Seconds, ms=Milliseconds, m=Months, q=quarter, y=Year

noOfIntervals  - Number of intervals to be added in parameter 1 date object. Positive interval number adds interval in date and returns future date. Negative interval number  subtracts interval and returns past date.


Returns

 Returns date object.

Example

var date = DateUtil.stringToDate(“04-11-2022” , “dd-MM-yyyy”);

DateUtil. addIntervalToDate(date , ‘w’ , 1); returns a new date object for “18-11-2022” date.

String

dateToString(Date date, String dateFormat )

Returns formatted string value for specified date object as per specified format.


Parameters

date – Date object.

dateFormaat– Specify the date format in which date needs to be formatted. For example, dd-MM-yyyy,  MMM-dd-yyyy hh:mm:ss


Returns

 Returns the formatted string.


Example

var date = DateUtil.stringToDate(“04-11-2022” , “dd-MM-yyyy”);

DateUtil. dateToString (date , “yyyy-MM-dd”); returns string “2022-11-04”.


Date

stringToDate(String dateString, String dateFormat)

Converts string date value in Date object. 


Parameters

dateString – Date value in string which needs to be converted into a date object.

dateFormaat– Specify the date format in which dateString is formatted. For example, dd-MM-yyyy,  MMM-dd-yyyy hh:mm:ss


Returns

 Returns the Date object

Example

DateUtil.stringToDate(“04-11-2022” , “dd-MM-yyyy”);  returns date object for 4th november 2022.


Number

noOfIntervals(String returnIntervalType, Date startDate, Date endDate)

Returns the number of intervals between two date ranges.


Parameters

returnIntervalType  – Specify the type of interval in which the date difference needs to be calculated. Valid values are: d=Days, w=Weeks, h=Hours, n=Minutes, s=Seconds, ms=Milliseconds, m=Months, q=quarter, y=Year

startDate – Start date of range

endDate – End date of range


Returns  

Number of intervals as per specified interval type. It returns absolute int value.For example , if no of intervals value is 2.6 then it will return 2.

Example

var startDate = DateUtil.stringToDate(“15-01-2020” , “dd-MM-yyyy”);

var endDate = DateUtil.stringToDate(“04-09-2021” , “dd-MM-yyyy”);

var date = DateUtil.stringToDate(“12-06-2022” , “dd-MM-yyyy”);

DateUtil. noOfIntervals(“d” , startDate , endDate ); returns 598 days.

DateUtil. noOfIntervals(“m” , startDate , endDate ); returns 20 months.

DateUtil. noOfIntervals(“d” , firstDateOfAbsoluteInterval (“m” , ”M6” , 0 , 2022 ,false) , lastDateOfAbsoluteInterval (“m” , ”M6” , 0 , 2022 ,false);   returns 29 days.

Date

firstDateOfAbsoluteInterval(String intervalType , String intervalValue , int month , int year , boolean isFY)

Returns the first date for the specified interval.


Parameters

intervalType – specifies value of interval type for “intervalValue” in argument2 . Valid values are: w=Week of year,W=Week of month, m=Months, q=quarter, f=Half Year, y=year. 

intervalValue – specifies value for interval.

year – specifies value for year. If the financial year value is 2023-24 then provide the year value as 2023.

month – specifies value for month.Valid values are 1-12. If the financial year starts from april “month value 1” represents “April” month.    

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial year.

Returns

Date object for first date of given interval.

Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.firstDateOfAbsoluteInterval(“m” , “4” ,  0 , 2022 , false ); return date object for “01-04-2022” date.

DateUtil.firstDateOfAbsoluteInterval(“q” , “Q3” ,  0 , 2022 , false ); return date object for “01-07-2022” date.

DateUtil.firstDateOfAbsoluteInterval(“w” , ”W4” , DateUtil. getMonth(date , false , false ,false) , DateUtil.getYear(date , false), false); returns date object for “23-10-2022” date.

DateUtil.firstDateOfAbsoluteInterval(“y” , “0” ,  0 , 2022 , true); return date object for “01-04-2022” date.


Date

firstDateOfAbsoluteYear(int year , boolean isFY)

Returns the first date for the specified year.

Parameters

year – specifies value for year. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.


Returns

Returns the date object for the first date of a given year.


Example

DateUtil.firstDateOfAbsoluteYear(2022 , false ); returns the date object for “01-01-2022”.

DateUtil.firstDateOfAbsoluteYear(2022 , true); returns the date object for “01-04-2022”.

Date

firstDateOfAbsoluteHalfYear(int halfYear , int year , boolean isFY)

Returns the first date for the specified half year.

Parameters 

halfYear – specifies value for half year. Valid values are 1-2.

year – specifies year in which argument1 halfYear value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Date object for first date of given half year.

Example

DateUtil.firstDateOfAbsoluteHalfYear(1 , 2022 , false); return date object for “01-01-2022” date.

DateUtil.firstDateOfAbsoluteHalfYear(1 , 2022 , true); return date object for “01-04-2022” date.

Date

firstDateOfAbsoluteQuarter(int quarter , int year , boolean isFY)

Returns the first date for the specified quarter.

Parameters 

quarter – specifies value for quarter.Valid values are 1-4.

year – specifies year in which argument1 quarter value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Date object for first date of given quarter.

Example

DateUtil. firstDateOfAbsoluteQuarter(3 , 2022 , false); return date object for “01-07-2022” date.

DateUtil. firstDateOfAbsoluteQuarter(3 , 2022 , true); return date object for “01-10-2022” date.

Date

firstDateOfAbsoluteMonth(int month , int year , boolean isFY)

Returns the first date for the specified month.

Parameters 

month – specifies value for month.Valid values are 1-12. If the financial year starts from april “month value 1” represents “April” month.

year – specifies year in which argument1 month value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY -  If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Date object for first date of given month.

Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.firstDateOfAbsoluteMonth(6 , 2020,false); returns date object for “01-06-2020”.

DateUtil.firstDateOfAbsoluteMonth(4, DateUtil.getYear(date , false)  ); returns date object for “01-04-2022”.

DateUtil.firstDateOfAbsoluteMonth(1 , 2020,true); returns date object for “01-04-2020”.

Date

firstDateOfAbsoluteWeekOfMonth(int weekOfMonth , int month, int year , boolean isFY)

Returns the first date for the specified week.

Parameters 

weekOfMonth – specifies value for week.Valid values are 1-5.

month – specifies month in which argument1 week value belongs to. If the financial year starts from april “month value 1” represents “April” month.

year – specifies year in which argument2 month value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

Returns 

Date object for first date of given week. If the start day of the month is Wednesday then the first date for 1 week returns for Wednesday instead of Sunday.

Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.firstDateOfAbsoluteWeek(“W4” , DateUtil. getMonth(date , false) , DateUtil.getYear(date , false), false); returns date object for “23-10-2022” date.

DateUtil.firstDateOfAbsoluteWeek(“W4” , DateUtil. getMonth(date , true) , DateUtil.getYear(date , true), true); returns date object for “23-01-2022” date.

Date

firstDateOfAbsoluteWeekOfYear(int weekOfYear , int year ,  boolean isFY)

Returns the first date for the specified week of year.

Parameters 

weekOfYear – specifies value for week of year.Valid values are 1-53.

year – specifies year in which argument1 weekOfYear value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns 

Date object for first date of given week of year.

Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.firstDateOfAbsoluteWeekOfYear(8 , DateUtil.getYear(date , false), false);  returns date object for “13-02-2022” date.

DateUtil.firstDateOfAbsoluteWeekOfYear(8 , DateUtil.getYear(date , true), true);  returns date object for “15-05-2022” date.


Date

firstDateOfRelativeInterval(String intervalType , int  intervalValue , boolean isFY)

Returns the first date for the specified relative interval. 

Parameters

intervalType – Interval type from specified relative interval value for which first date is returned. Valid values are:w=Week of year,W=Week of month, m=Months, q=quarter, f=Half Year, y=year. 

intervalValue – Relative interval value of interval type specified in “intervalType” parameter. Valid values are: 0-Current interval, negative number - Past interval, positive number - future interval.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial year.

Returns

Date object of first date of the interval

Example

If current date is 2022-09-22

DateUtil.firstDateOfRelativeInterval(‘w’ , -2 , false);  returns date object for “2022-09-11”

DateUtil.firstDateOfRelativeInterval(‘m’ , -3 , false);  returns date object for “2022-06-01”

DateUtil.firstDateOfRelativeInterval(‘y’ , -1 , true);  returns date object for “2021-04-01”

Date

firstDateOfRelativeYear(int relativeYear, boolean isFY )

Returns the first date for the specified relative year.


Parameters 

 

relativeYear – Relative interval value for year. Valid values are: 0-Current year, negative number – Past year, positive number – next year. For example if the current year is 2022 then -2 represents the year 2020.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.  

Returns 

Returns the first date for the specified relative year.

Example

If current date is 2022-09-22

DateUtil.firstDateOfRelativeYear( -3 ,false );  returns date object for “2019-01-01”

DateUtil.firstDateOfRelativeYear( -3 ,true );  returns date object for “2019-04-01”

Date

firstDateOfRelativeHalfYear(int relativeHalfYear, boolean isFY)

Returns the first date for the specified relative half year.

Parameters 

relativeHalfYear – Relative interval value for half year. Valid values are: 0-Current half year, negative number - Past half year, positive number – next half year.For example if current date is 20-03-2022 then value -3 represents 2nd half year of 2020.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns 

Returns the first date for the specified relative half year.

Example

If current date is 2022-09-22

DateUtil.firstDateOfRelativeHalfYear( -1 , false) returns date object for “2022-01-01”.

DateUtil.firstDateOfRelativeHalfYear( -1 , true) returns date object for “2022-04-01”.

Date

firstDateOfRelativeQuarter(int relativeQuarter, boolean isFY)

Returns the first date for the specified relative quarter.


Parameters 

relativeQuarter – Relative interval value for quarter. Valid values are: 0-Current quarter, negative number - Past quarter, positive number – next quarter.For example if current date is 20-03-2022 then value -3 represents 2nd quarter of 2021.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.


Returns 

Returns the first date for the specified relative quarter.

Example

If current date is 2022-09-22

DateUtil.firstDateOfRelativeQuarter( 2 , false); returns date object for “2022-10-01”.

DateUtil.firstDateOfRelativeQuarter( 2 , true); returns date object for “2023-01-01”.

Date

firstDateOfRelativeMonth(int relativeMonth )

Returns the first date for the specified relative month.


Parameters 

relativeMonth – Relative interval value for month. Valid values are: 0-Current month, negative number – Past month, positive number – next month. For example if the current date is 20-03-2022 then value -5 represents October month of 2021.

Returns 

Returns the first date for the specified relative month.

Example

If current date is 2022-09-22

DateUtil.firstDateOfRelativeMonth( -3 ); returns date object for “2022-06-01”

Date

firstDateOfRelativeWeek(int relativeWeek )

Returns the first date for the specified relative week.


Parameters 

relativeWeek – Relative interval value for week. Valid values are: 0-Current week, negative number - Past week, positive number – next week. For example if the current date is 20-03-2022 then value -2 represents the 2nd week of march 2022.

Returns 

Returns the first date for the specified relative week.

Example

If the current date is 2022-09-22.

DateUtil.firstDateOfRelativeWeek( -2 ); returns date object for “2022-09-04”.

Date

lastDateOfAbsoluteInterval(String intervalType , String intervalValue , int month , int year , boolean isFY)

Returns the last date for the specified interval.

Parameters

intervalType – specifies value of interval type for “intervalValue” in argument2. Valid values are: w=Week of year,W=Week of month, m=Months, q=quarter, f=Half Year, y=year. interval.

intervalValue – specifies value for interval.

year – specifies value for year. If the financial year value is 2023-24 then provide the year value as 2023.

month – specifies value for month.Valid values are 1-12. If the financial year starts from april “month value 1” represents “April” month.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial year.

Returns

Date object of last date of the interval.

Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.lastDateOfAbsoluteInterval(“m” , “4” ,  0 , 2022 , false ); return date object for “30-04-2022” date.

DateUtil.lastDateOfAbsoluteInterval(“q” , “Q3” ,  0 , 2022 , false ); return date object for “30-09-2022” date.

DateUtil.lastDateOfAbsoluteInterval(“w” , ”W4” , DateUtil. getMonth(date , false , false ,false)DateUtil.getYear(date , false), false); returns date object for “29-10-2022” date.

DateUtil.lastDateOfAbsoluteInterval(“m” , “4” ,  0 , 2022 , true); return date object for “31-07-2022” date.

Date

lastDateOfAbsoluteYear(int year , boolean isFY)

Returns the last date for the specified year.

Parameters

year – specifies value for year. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.


Returns

Returns the date object for the last date of a given year.


Example

DateUtil.lastDateOfAbsoluteYear(2022 , false ); returns the date object for “31-12-2022”.

DateUtil.lastDateOfAbsoluteYear(2022 , true); returns the date object for “31-03-2023”.


Date

lastDateOfAbsoluteHalfYear(int halfYear , int year , boolean isFY)

Returns the last date for the specified half year.

Parameters 

halfYear – specifies value for half year. Valid values are 1-2.

year – specifies year in which argument1 halfYear value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Date object for the last date of the given half year.


Example

DateUtil.lastDateOfAbsoluteHalfYear(1 , 2022 , false); return date object for “30-06-2022” date.

DateUtil.lastDateOfAbsoluteHalfYear(1 , 2022 , true); return date object for “30-09-2022” date.

Date

lastDateOfAbsoluteQuarter(int quarter , int year , boolean isFY)

Returns the last date for the specified quarter.

Parameters 

quarter – specifies value for quarter.Valid values are 1-4.

year – specifies year in which argument1 quarter value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Date object for last date of given quarter.


Example

DateUtil.lastDateOfAbsoluteQuarter(3 , 2022 , false); return date object for “30-09-2022” date.

DateUtil.lastDateOfAbsoluteQuarter(3 , 2022 , true); return date object for “31-12-2022” date.

Date

lastDateOfAbsoluteMonth(int month , int year , boolean isFY)

Returns the last date for the specified month.

Parameters 

month – specifies value for month.Valid values are 1-12. If the financial year starts from april “month value 1” represents “April” month.

year – specifies year in which argument1 month value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY -  If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Date object for last date of given month.

Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.lastDateOfAbsoluteMonth(6 , 2020 , false ); returns date object for “30-06-2020”.

DateUtil.lastDateOfAbsoluteMonth(4 , DateUtil.getYear(date , false)  ,false ); returns date object for “30-04-2022”.

DateUtil.lastDateOfAbsoluteMonth(6 , 2020 , true); returns date object for “30-09-2020”.

Date

lastDateOfAbsoluteWeekOfMonth(int weekOfMonth , int month, int year , boolean isFY)

Returns the last date for the specified week.


Parameters 

weekOfMonth – specifies value for week.Valid values are 1-5.

month – specifies month in which argument1 week value belongs to. If the financial year starts from april “month value 1” represents “April” month.

year – specifies year in which argument2 month value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.


Returns 

Date object for last date of given week. If the last day of the month is Wednesday then the first date for last week returns a date for Wednesday instead of Sunday.


Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.lastDateOfAbsoluteWeek(4 , DateUtil. getMonth(date , false) , DateUtil.getYear(date , false), false) ;returns date object for “29-10-2022” date.

DateUtil.lastDateOfAbsoluteWeek(4 , DateUtil. getMonth(date , true) , DateUtil.getYear(date , true), true) ;returns date object for “28-01-2022” date.


Date

lastDateOfAbsoluteWeekOfYear(int weekOfYear , int year ,  boolean isFY)

Returns the last date for the specified week of year.


Parameters 

weekOfYear – specifies value for week of year.Valid values are 1-53.

year – specifies year in which argument1 weekOfYear value belongs to. If the financial year value is 2023-24 then provide the year value as 2023.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.


Returns 

Date object for last date of given week of year.


Example

var date = DateUtil.stringToDate(“12-10-2022” , “dd-MM-yyyy”);

DateUtil.lastDateOfAbsoluteWeekOfYear(8 , DateUtil.getYear(date , false), false); returns date object for “13-02-2022” date.

DateUtil.lastDateOfAbsoluteWeekOfYear(8 , DateUtil.getYear(date , true), true); returns date object for “21-05-2022” date.


Date

lastDateOfRelativeInterval(String intervalType , String intervalValue , boolean isFY)

Returns the last date for the specified relative interval. 


Parameters

intervalType – Interval type from specified relative interval value for which last date is returned. Valid values are: w=Week of year,W=Week of month, m=Months, q=quarter, f=Half Year, y=year.

intervalValue – specifies value for interval.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial year.


Returns

Date object of last date of the interval.


Example

If current date is 2022-09-22

DateUtil.lastDateOfRelativeInterval(‘w’ , “W2” , false); returns date object for “2022-09-17”

DateUtil.lastDateOfRelativeInterval(‘m’ , “M3” , false); returns date object for “2022-03-31”

DateUtil.lastDateOfRelativeInterval(‘m’ , “M3” , true); returns date object for “2022-06-30”

Date

lastDateOfRelativeYear(int relativeYear, boolean isFY )

Returns the last date for the specified relative year.

Parameters 

 relativeYear – Relative interval value for year. Valid values are: 0-Current year, negative number – Past year, positive number – next year. For example if the current year is 2022 then -2 represents the year 2020.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns 

Returns the first date for the specified relative year.

Example

If current date is 2022-09-22

DateUtil.firstDateOfRelativeYear( -3 ,false ); returns date object for “2019-12-31”

DateUtil.firstDateOfRelativeYear( -3 ,true ); returns date object for “2020-03-31”

Date

lastDateOfRelativeHalfYear(int relativeHalfYear, boolean isFY)

Returns the last date for the specified relative half year.

Parameters 

relativeHalfYear – Relative interval value for half year. Valid values are: 0-Current half year, negative number - Past half year, positive number – next half year. For example if the current date is 20-03-2022 then value -3 represents the 2nd half year of 2020.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns 

Returns the last date for the specified relative half year.

Example

If current date is 2022-09-22

DateUtil.lastDateOfRelativeHalfYear( -1 , false); returns date object for “2022-06-31”.

DateUtil.lastDateOfRelativeHalfYear( -1 , true); returns date object for “2022-03-31”.

Date

lastDateOfRelativeQuarter(int relativeQuarter, boolean isFY)

Returns the last date for the specified relative quarter.

Parameters 

relativeQuarter – Relative interval value for quarter. Valid values are: 0-Current quarter, negative number - Past quarter, positive number - next quarter. For example if the current date is 20-03-2022 then value -3 represents the 2nd quarter of 2021.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns 

Returns the last date for the specified relative quarter.

Example

If current date is 2022-09-22

DateUtil.lastDateOfRelativeQuarter( 1 , false); returns date object for “2022-12-31”.

DateUtil.lastDateOfRelativeQuarter( 1 , true); returns date object for “2022-12-31”.

Date

lastDateOfRelativeMonth(int relativeMonth)

Returns the last date for the specified relative month.

Parameters 

relativeMonth – Relative interval value for month. Valid values are: 0-Current month, negative number - Past months, positive number – next months. For example if the current date is 20-03-2022 then value -5 represents October month of 2021.

Returns 

Returns the last date for the specified relative month.

Example

If current date is 2022-09-22

DateUtil.lastDateOfRelativeMonth( -3 , false); returns date object for “2022-06-30”

DateUtil.lastDateOfRelativeMonth( -3 , true); returns date object for “2022-06-30”

Date

lastDateOfRelativeWeek(int relativeWeek)

Returns the last date for the specified relative week.

Parameters 

relativeWeek – Relative interval value for week. Valid values are: 0-Current week, negative number - Past week, positive number - next week.For example if current date is 20-03-2022 then value -2 represents 2nd week of march 2022.

Returns 

Returns the last date for the specified relative week.

Example

If current date is 2022-09-22

DateUtil.lastDateOfRelativeWeek(2); returns date object for “2022-09-17”.


Number

getYear(Date date , boolean isFY)

Returns year represented by specified date

Parameters

Date – date object.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Returns year represented by specified date

Example

var date = DateUtil.stringToDate(“15-03-2020” , “dd-MM-yyyy”);

DateUtil.getYear(date , false); returns 2020.

DateUtil.getYear(date , true); returns 2019.

Number

getQuarter(Date date , boolean isFY )

Returns quarter represented by specified date

Parameters

Date – date object.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year. 

Returns

Returns quarter represented by specified date.

Example

var date = DateUtil.stringToDate(“19-11-2020” , “dd-MM-yyyy”);

DateUtil.getQuarter(date , false ); returns 4.

DateUtil.getQuarter(date , true); returns 3.

String

getQuarterName(Date date , boolean isFY )

Returns quarter name represented by specified date

Parameters

Date – date object.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year. 

Returns

Returns quarter name represented by specified date. Returns value “Q1” to “Q4”.

Example

var date = DateUtil.stringToDate(“19-11-2020” , “dd-MM-yyyy”);

DateUtil.getQuarterName(date , false ); returns “Q4”.

DateUtil.getQuarterName(date , true); returns “Q3”.

Number

getMonth(Date date , boolean isFY)

Returns month represented by specified date

Parameters

Date – date object.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year. 


Returns

Returns month represented by specified date

Example

var date = DateUtil.stringToDate(“19-11-2020” , “dd-MM-yyyy”);

DateUtil.getMonth(date ,  false); returns 11.

DateUtil.getMonth(date ,  true); returns 8.

String

getMonthName(Date date )

Returns full month name represented by specified date.

Parameters

Date – date object. 


Returns

Returns full month name represented by specified date. For example “January” , “February” ,”March” etc.


Example

var date = DateUtil.stringToDate(“19-11-2020” , “dd-MM-yyyy”);

DateUtil.getMonthName(date ,  false); returns “November”.

DateUtil.getMonthName(date ,  true); returns “November”.

Number

getDayOfMonth(Date date )

Returns day of month represented by specified date.


Parameters

Date – date object.


Returns

Returns day of month represented by specified date

Example

var date = DateUtil.stringToDate(“15-04-2020” , “dd-MM-yyyy”);

DateUtil. getDate(date ); returns 15.

Number

getWeekDay(Date date)

Returns the day of the week represented by this date. The returned value (0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday) represents the day of the week that contains or begins with the instant in time represented by this Date object.

Parameters

Date – date object.

returnIntervalName – if true returns week day name otherwise returns no of week day.

 

Returns

Returns day of week represented by specified date. The returned value (0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday).


Example

var date = DateUtil.stringToDate(“15-04-2020” , “dd-MM-yyyy”);

DateUtil.getWeekDay(date); returns 3.


String

getWeekDayName(Date date)

Returns the name for the day of the week represented by this date. The returned value (Sunday,  Monday, Tuesday,  Wednesday,  Thursday, Friday,  Saturday) represents the day of the week that contains or begins with the instant in time represented by this Date object.


Parameters

Date – date object. 


Returns

Returns name for day of week represented by specified date.


Example

var date = DateUtil.stringToDate(“15-04-2020” , “dd-MM-yyyy”);

DateUtil.getWeekDay(date); returns Wednesday.


Number

getHours(Date date)

Returns hours represented by specified date.


Parameters

Date – date object.


Returns

Returns hours represented by specified date.


Example

var date = DateUtil.stringToDate(“23-08-2020 10:30:20” , “dd-MM-yyyy HH:mm:ss”);

DateUtil.getHours(date); returns 10.

Number


getMinutes(Date date)

Returns minutes represented by specified date.


Parameters

Date – date object.


Returns

Returns minutes represented by specified date.


Example

var date = DateUtil.stringToDate(“15-04-2020 10:30:20” , “dd-MM-yyyy HH:mm:ss”);

DateUtil.getMiniutes(date); returns 30.



Number

getSeconds(Date date)

Returns seconds represented by specified date


Parameters

Date – date object.


Returns

Returns seconds represented by the specified date.


Example

var date = DateUtil.stringToDate(“15-04-2020 10:30:20” , “dd-MM-yyyy HH:mm:ss”);

DateUtil.getSeconds(date); returns 20.



Number

getTimeInMilliSeconds(Date date)

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the specified Date object.


Parameters

Date – date object.


Returns

the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.


Example

var date = DateUtil.stringToDate(“14-11-2022” , “dd-MM-yyyy”);

DateUtil. getTimeInMilliSeconds (date); returns 61629120000000.



Number

getWeekOfMonth(Date date)

Returns week of month from specified date.

Parameters

Date – date object.


Returns

Returns week of month from specified date.


Example

var date = DateUtil.stringToDate(“14-11-2022” , “dd-MM-yyyy”);

DateUtil.getWeekOfMonth(date); returns 3.

Number

getWeekOfYear(Date date , boolean isFY)

Returns the week of year from the specified date.


Parameters

Date – date object.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Returns the week of year from the specified date.

Example

var date = DateUtil.stringToDate(“14-11-2022” , “dd-MM-yyyy”);

DateUtil.getWeekOfYear(date,false); returns 47.

DateUtil.getWeekOfYear(date,true); returns 33.

Number

getDayOfYear(Date date , boolean isFY)

Returns day of year from specified date.

Parameters

Date – date object.

isFY – If false calculates no. of intervals as per calendar year otherwise as per Financial Year.

Returns

Returns day of year from specified date.

Example

var date = DateUtil.stringToDate(“14-11-2022” , “dd-MM-yyyy”);

DateUtil.getDayOfYear(date , false); returns 318.

DateUtil.getDayOfYear(date , true); returns 228.

Number

getNetWorkDays(Date startDate , Date endDate , int weekend , Date[] holidays)        

Returns the number of whole workdays between two dates (inclusive).

Parameters

startDate – A date that represents the start date.

endDate -  A date that represents the end date.

Weekend - Indicates the days of the week that are weekend days. Valid values are as below.

1 or omitted: Saturday, Sunday

2: Sunday, Monday

3: Monday, Tuesday

4: Tuesday, Wednesday

5: Wednesday, Thursday

6: Thursday, Friday

7: Friday, Saturday

11: Sunday only

12: Monday only

13: Tuesday only

14: Wednesday only

15: Thursday only

16: Friday only

17: Saturday only


Holidays - One or more dates that are to be excluded from the working day calendar.

Returns

An integer number of whole workdays.

Example

var startDate = DateUtil.stringToDate(“23-05-2022” , “dd-MM-yyyy”);

var   = DateUtil.stringToDate(“30-05-2022” , “dd-MM-yyyy”);

var holiday = DateUtil.stringToDate(“30-05-2022” , “dd-MM-yyyy”);

DateUtil. getNetWorkDays(startDate , endDate , 1 , [holiday]); returns 5.

 




EmailUtil Function


Return

Description

Boolean

sendMail(String fromEmailId , String toEmailId , String[]  ccEmailIds , String mailSubject , String mailBody , File[]  attachmentFiles , String charset , Number emailBodyMimeType)

Send email to the receiver.

Note : This method can throw an Exception when failed to send an email. This is useful for error reporting and to diagnose why failed to send an email.

Parameters

fromEmailId – sender email id.

toEmailId – receiver email id.

ccEmailIds – cc email ids.

mailSubject – email subject text.

mailBody – mail body text.

attachmentFiles  – array of files need to be attached in the mail body.

charset – the charset to use for text . Valid values are “UTF-8” , “UTF-16” , “UTF-16LE” , “UTF-16BE” , “UTF-32” , “ISO-8859-9” etc.

emailBodyMimeType – mime type for email body. Valid values are 0=text , 1=html.

Returns

Returns true if the email is sent successfully.

Example


var attachment = [[“/home/user/Desktop/Sales.png”],[“/home/user/Desktop/Sales.csv”]]

EmailUtil.sendMail("test@gmail.com", "abc@gmail.com", "", "This is Script mail", "This is test script mail here", attachment , "UTF-8", 0);



MathUtil functions

Return type

Description

Number

abs(Number num)

Returns the absolute value for the specified number.

Parameters

num - The number whose absolute value is to be determined.

Returns

The absolute value of the specified number

Example

MathUtil.abs(-5.44); returns 5.44

MathUtil.abs(6.7); returns 6.7


Number

sin(Number angle)

Returns the sine of the given angle.

Parameters

Angle - The angle in radians for which you want the sine.

Returns

Returns the sine of the given angle.

Example

MathUtil.sin(MathUtil.pi()); returns 1.22

MathUtil.sin(MathUtil.pi()/2); returns 1.0

MathUtil.sin(MathUtil.toRadians(30)); returns 0.5


Number

cos(Number angle)

Returns the cosine of the given angle.

Parameters

Angle - The angle in radians for which you want the cosine.

Returns

Returns the cosine of the given angle.

Example

MathUtil.cos(1.047); returns 0.5001711

MathUtil.cos(MathUtil.toRadians(60)); returns 0.5

Number

tan(Number angle)

Returns the tangent of the given angle.

Parameters

Angle - The angle in radians for which you want the tangent.

Returns

Returns the tangent of the given angle.

Example

MathUtil.tan(0.785); returns 0.99920

MathUtil.tan(MathUtil. toRadians(45)); returns 0.9999999


Number

asin(Number num)

Returns the arcsin or inverse sine of the given number.

Parameters

num - The number for which you want arcsine.

Returns

Returns the arcsine of the given number.

Example

MathUtil.asin(0.5); returns -0.523598776


Number

acos(Number num)

Returns the arccosine or inverse cosine of the given number.

Parameters

num - The number for which you want the arccosine.

Returns

Returns the arccosine of the given number.

Example

MathUtil.acos(-0.5); returns 2.094395102

Number

atan(Number num)

Returns the arctangent or inverse tangent of the given number.

Parameters

num - The number for which you want the arctangent.

Returns

Returns the arctangent of the given number.

Example

MathUtil.atan(0.785); returns 0.665527

MathUtil.atan(MathUtil.toRadians(45)); returns 0.6657737500283538


Number

sinh(Number num)

Returns the hyperbolic sine of the specified number. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Euler's number.

Parameters

num - The number whose hyperbolic sine is to be returned.

Returns

Returns the hyperbolic sine of a number.

Example

MathUtil.sinh(0); return 0.0

MathUtil.sinh(2); returns 3.626860407847019.


Number

cosh(Number num)

Returns the hyperbolic cosine of specified number. The hyperbolic cosine of x is defined to be (ex + e-x)/2 where e is Euler's number.


Parameters

num - The number whose hyperbolic cosine is to be returned.

Returns

Returns the hyperbolic cosine of a number.

Example

MathUtil.cosh(0); returns 1.0

MathUtil.cosh(2); returns 3.7621956910836314.

Number

tanh(Number num)

Returns the hyperbolic tangent of the specified number. The hyperbolic tangent of x is defined to be (ex - e-x)/(ex + e-x) where e is Euler's number.


Parameters

num - The number whose hyperbolic tangent is to be returned.

Returns

Returns the hyperbolic tangent of a number.

Example

MathUtil.tanh(0); returns 0.0.

MathUtil.tanh(-2); returns -0.964028.


Number

pi()

Returns the double value for pi.


Returns

Returns the double value for pi.


Example

MathUtil.pi(); returns 3.141592653589793.

Number

toDegrees(Number angrad)

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

Parameters

angrad – an angle , in radians.


Returns 

The measurement of the angle angrad in degrees.

Example

MathUtil.toDegrees(0.55); returns 31.5126

MathUtil.toDegrees(1.2218); returns 70.00398340908399.

Number

toRadians(Numer angdeg)

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Parameters

angdeg – an angle , in degrees.


Returns

The measurement of the angle angdeg in radians.


Example

MathUtil.toRadians(45); returns 0.7853981633974483.

MathUtil.toRadians(60); returns 1.0471975511965976. 

Number

ceiling(Number num)

Returns the smallest integer number which is greater than or equal to the given number.

Parameters

num - The number whose ceiling value is to be returned.


Returns

Returns ceiling value of given number.


Example

MathUtil.ceiling(7.6); returns 8.0.

MathUtil.ceiling(4); returns 4.0.

Number

floor(Number num)

Returns the largest integer number which is less than or equal to the given number.

Parameters

num - The number whose floor value is to be returned.


Returns

Returns floor value of given number.


Example

MathUtil.floor(7.6); returns 7.0.

MathUtil.floor(4); returns 4.0.

Number

exp(Number power)

Returns e raised to the power of a given number. The constant e equals 2.71828182845904, the base of the natural logarithm. 

Parameters

power – The power of e.

Returns

Returns e with given power.

Example

MathUtil.exp(1); returns 2.71828182845904.

MathUtil.exp(4); returns 54.598150033144236.

Number

fact(Number num)

Returns the factorial of the given number.

Parameters

num - The number whose factorial value is to be returned.

Returns

Returns the factorial of the given number.

Example

MathUtil.fact(3); returns 6.

MathUtil.fact(5); returns 120.


Number

gcd(Number[] nums)

Returns the greatest common divisor of two or more numbers.


Parameters

nums – numbers array for which gcd is to be returned.


Returns

Returns the greatest common divisor of two or more integers.


Example

MathUtil.gcd([5,2]); returns 1;

MathUtil.gcd([24,36]); returns 12;

Number

lcm (Number[] nums)

Returns the least common multiple of two or more numbers.

Parameters

nums – numbers array for which lcm is to be returned.

Returns

Returns the least common multiple of two or more integers.

Example

MathUtil.lcm([5,2]); returns 10;

MathUtil.lcm([24,36]); returns 72;

Number

log(Number num , Number base)

Returns the logarithm of a number to the base you specify.


Parameters

num - The positive number for which you want the logarithm.

base - The base of the logarithm.

Returns

Returns the logarithm of a number with a specified base.

Example

MathUtil.log(100 , 10); returns 4.605170185988092.

Number

log10(Number num )

Returns the logarithm of a number to the base 10 .


Parameters

num - The positive number for which you want the logarithm.

Returns

Returns the logarithm of a number with base 10.

Example

MathUtil.log10(100 ); returns 2.0.

Number

min(Number num1 , Number num2)

Returns min from given numbers.

Parameters

num1 - First number to find out if it is smaller than the second number.

num2 - Second number to find out if it is smaller than the first number. 

Returns

Min number from given number.

Example

MathUtil.min(10 , 15); return 10.

Number

max(Number num1 , Number num2)

Returns max from given numbers.

Parameters

num1 - First number to find out if it is larger than the second number.

num2 - Second number to find out if it is larger than the first number. 

Returns

Max number from given number.

Example

MathUtil.max(10 , 15); return 15.

Number

mod(Number dividend , Number divisor)

Returns modulus of two numbers.


Parameters

dividend - The number to be divided.

divisor - The number by which the dividend has to be divided.


Returns

Returns modulus of two numbers.

Example

MathUtil.mod(15,2); returns value 1.

Number

round(Number num , Number round)

Returns a number rounded to a specified number of decimal places.


Parameters

num - The number to be rounded

round - The number of places to which the number is to be rounded.


Returns

Returns a number rounded to a specified number of decimal places.

Example

MathUtil.round(39984.04, 1); returns 39984.0.

MathUtil.round(12.28, 1); returns 12.3.


Number

pow(Number num , Number power)

Returns the result of a number raised to a power.

Parameters

num – The base number.

power - The exponent to which the base number is raised.

Example

MathUtil.pow(5,2); returns 25.

Number

rand()

Returns a random number greater than or equal to 0 and less than 1.

Returns

Returns a random number between 0 to 1.

Example

MathUtil.rand(); returns 0.7046756849245908

Number

randbetween(Number bottom , Numer top)

Returns a random number in the range between two numbers which is specified.

Parameters

bottom – The smallest integer the function will return.

top - The largest integer the function will return.

Returns

Returns a random number between ranges.

Example

MathUtil.randbetween(10,100); return 39.0.

Number

sqrt(Number num)

Returns the square root of the number.

Parameters

Num – The number for which square root is to be returned.

Returns 

A square root of number.

Example

MathUtil.sqrt(25); returns 5.0.

Number

truncate(Number num , Number scale)

Returns a number truncated to a specified number of decimal places.

Parameters

num - The Number to be truncated.

scale - The scale of the truncation.

Returns

Returns a number truncated to a specified number of decimal places.

Example

MathUtil.truncate( 54913648.12, 1); returns 54913648.10

MathUtil.truncate( 54913648.12, 0); returns 54913648.00


Logger functions

Return type

Description


initializeLogger(String strFilePath)

Initialize Logger object for specified path which we set in parameter strFilePath.

Parameters

strFilePath - complete file path of log file.


Example

Logg

Logger.initializeLogger(“"D:\\log\\log.txt”);


printLog(String strLog)

write the text in a log  file.

Parameters

strLog - text which is written in a log file.


Example

Logger.printLog(“Step1-Start process”);



closeLogger()

Close the log file and close the logger object.


Example

Logger.closeLogger();



printInfoInApplicationLog(String text)

Write an info log in Smarten Application Log.


Parameters

text- text which is written in a Smarten Application file.


Example

Logger.printInfoInApplicationLog(“Step1-Start process”);



printDebugInApplicationLog(String text)

Write a debug log in Smarten Application Log.


Parameters

text- text which is written in a Smarten Application file.


Example

Logger.printDebugInApplicationLog(“Step1-Start process”);


printErrorInApplicationLog(Throwable e)

Write error trace in Smarten Application Log.

Parameters

e- error object  written in a Smarten Application file.


Example

Logger.printErrorInApplicationLog(e);





Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article