Functions Script

The functions script file is used to contain any functions or commands that you wish to make available to all scripts. This makes for easier script management by placing the fumnctions in a single location. Using a single file to contain your functions also makes the scripts more portable, and allows for less re-coding of the same processes as the functions are available to any transaction, being separate from the transaction-specific scripts. An example from a functionsSystem.sjs file is shown below.

/*
**	Open Excel file
*/
function open_excel(filename)
{
    if(g_ExcelApp == void 0)
	g_ExcelApp = new ActiveXObject('Excel.Application');
    g_ExcelBook = g_ExcelApp.Workbooks.Open(filename);
    g_ExcelApp.Visible = true;
    g_ExcelApp.ScreenUpdating = true;
}

/*
**	get first item level column number (needs to be populated in to a table)
*/
var firstItemColumn;
function get_first_item_column(activesheet){
	//find firstItemColumn
	var lastCol = 3;
	for (var nCol=2; nCol < lastCol; nCol++){
		if (activesheet.Cells(1,nCol).Value.indexOf(",") > -1){
			firstItemColumn = nCol;
			break;
		} else {
			lastCol++;
		}
	}
}


/*
**Check if Screen Control exists str = "F[Material]", str = '#[3,0]'
*/
function isControl(str) {
	return Reebok(str).isValid;
}

In this function script, we have entered several functions, thus making them more portable as previously explained and enabling you to call them from any script file, instead of replicating them in each relevant script. In this case we are perforoming operations related to the Excel data migration, but you can use the function script for any functions that you wish to have available to any transactions or processes.

Note: If you decide to create a function script, it is important to ensure that the script file is loaded in the logon script as previously demonstrated, otherwise the functions may not be available.