Terrasoft CRM 3.0 SDK > Examples > Files > IScriptUtilsExample.js
ContentsIndex
IScriptUtilsExample.js

 

Description
Body Source
//-----------------------------------------------------------------------------
// IScriptUtilsExample.js file
//-----------------------------------------------------------------------------
// There is described the usage of the IScriptUtils object in the example.
//-----------------------------------------------------------------------------
//@ Start Example

// Creating the database connection and the ScriptUtils object
var Connector = new ActiveXObject('TSDskObjectLibrary.DskConnector');
var ScriptUtils = new ActiveXObject('TSObjectLibrary.ScriptUtils');
var FileSystemObject = new ActiveXObject('Scripting.FileSystemObject');

// Constants of the displaying options of the dialogue window
var mrYes = 6;
var HelpContext = 1;
var mdtWarning = 0;
var mdbYes = 1;
var mdbIgnore = 64;
 
// The access level to read/write
var fatReadWrite = 2;

var ResultDir = new ActiveXObject('TSObjectLibrary.Value');
var StartDir = 'C:\\';

// Current month period
var dotCurrentMonth = 19;

// Message displaying function 
function ShowMessage(Str) {
    for (var i = 1; i < arguments.length; i++ ) {
        Str = Str.replace(new RegExp('%' + i), arguments[i]);
    }
    WScript.Echo(Str);
}

// Function of the reading and displaying the log file content
function ShowLog(Log) {
	var File = FileSystemObject.GetFile(Log.FileName);
	var Stream = File.OpenAsTextStream(1, -2);
	while (!Stream.AtEndOfStream) {
		StringsList.Add(Stream.ReadLine());
	}
	ShowMessage(StringsList.Text);
}

if (Connector.Login("Example of the IScriptUtils use")) {

	// Setting the connection object's value for the ScriptUtils object
	ScriptUtils.Connector = Connector;

	// The usage of the object's creation function
	StringsList = ScriptUtils.CreateObject('TSObjectLibrary.StringsList');

	// Defining whether the current user has the license to the module "?25"
	if (ScriptUtils.GetHasLicense('X25')) {
		ShowMessage("The current user has the license to the module 'X25'");
	}

	// Removing the all files of the temp directory of the operation system,
	// which names begins on 'TS' no matter the extension
	ScriptUtils.ClearTemporaryDirectory('TS*.*');

	// USI service formation based on the data of the module,
	// group path and service code
	ShowMessage(ScriptUtils.CombineUSIParts('X15', 'Reports\\Account',
	  'sq_AccountInProjects'));

	// Use of marks of the beginning and end of the long-term action
	ScriptUtils.BeginProcessing();
	ScriptUtils.Sleep(4000);
	ScriptUtils.EndProcessing();

	// The parental group receiving based on the USI
	var USI = 'X15\\Workspaces\\Contacts\\General\\Main Grid\\wnd_ContactEdit'
	ShowMessage("The group %2 is a parental group for the service %1", USI, 
	  ScriptUtils.ExtractParentUSI(USI));

	// The service code receiving based on the USI
	ShowMessage("The service %1 has the code %2", USI, ScriptUtils.ExtractUSICode(USI));

	// The service group path receiving based on the USI
	ShowMessage("The service %1 has the group path %2", USI, 
	  ScriptUtils.ExtractUSIGroupPath(USI));

	// The service module receiving based on the USI
	ShowMessage("The service %1 has the module %2", USI,
	  ScriptUtils.ExtractUSIModule(USI));

	// Defining whether the current user has the license to the module "Module"
	if (ScriptUtils.CheckLicense('Module')) {
		ShowMessage("The current user has the license to the module 'Module'");
	} else {
		ShowMessage("The current user has no license to the module 'Module'");
	}

	// Displaying the log file content
	ShowLog(Connector.Log);

	// Displaying the version of the TSCRM.exe file
	ShowMessage(ScriptUtils.GetFileVersion(Connector.WorkingDirectory + 
	    'TSCRM.exe'));

	var GroupUSI  = 'X15\\Workspaces\\Contacts\\General\\';
	if (ScriptUtils.GetIsUSIInGroup(USI, GroupUSI)) {
		ShowMessage("The service %1 belongs to the group %2", USI, GroupUSI);
	}

	// Displaying the start date and finish date of the period by its type
	var DateFrom = new ActiveXObject('TSObjectLibrary.Value');
	var DateTo = new ActiveXObject('TSObjectLibrary.Value');
	var Today = new Date().getVarDate();

	ScriptUtils.GetPeriodIntervalFromPeriodType(dotCurrentMonth, Today,
	    DateFrom, DateTo);
	ShowMessage("There is a start date of the period %1 and the finish date %2 for the date type 'Current month'", 
	    DateFrom.Value, DateTo.Value);

	// Generating the temporary file name with the specified prefix and extension
	ShowMessage(ScriptUtils.GetTempFileName('TSObject', 'tmp'));

	// Global unique identifier check for correctness
	var GUIDString = Connector.GenGUID();
	if (ScriptUtils.IsValidGUIDString(GUIDString)) {
		ShowMessage(
		  "%1 is a correct global unique identifier", 
		    GUIDString);
	}

	// Variable identifier name check for correctness
	var Ident = '4Ident';
	if (ScriptUtils.IsValidIdent(Ident)) {
		ShowMessage("%1 is a correct name of the global unique identifier", 
		    Ident);
	} else {
		ShowMessage("%1 is an incorrect name of the global unique identifier", 
		    Ident);
	}

	// Performing th string encryption
	ShowMessage("'TestString' after the encryption : %1",
	  ScriptUtils.OneWayCrypt('TestString'));

	// Displaying the warning dialogue window with the buttons  "Yes" and "Ignore"
	if (ScriptUtils.MessageDialog("Warning", mdtWarning, mdbYes + mdbIgnore, 
	    HelpContext) == mrYes) {
		ShowMessage("The 'Yes' has been pressed");
	} else {
		ShowMessage("The 'Ignore' has been pressed");
	}

	// Launching the selected executable file
	var Title = "Select program for launch";
	var FileName = new ActiveXObject('TSObjectLibrary.Value');
	if (ScriptUtils.OpenDialog(FileName, '*.exe', '*.exe', Title, "c:\\")) {
		ScriptUtils.OpenFile(FileName.Value, fatReadWrite);
	}
	
	// Displaying the dialogue window for folder selection
	if (ScriptUtils.SelectDirectory("Folder selection", StartDir, ResultDir)) {
		ShowMessage("%1 folder has been selected", ResultDir.Value);
	}
	
	// Displaying the dialogue window for file selection
	var Title = "Files opening";
	if (ScriptUtils.PromptForFileNames(FileName, '*.txt', '*.txt', Title, 'c:\\')) {
		ShowMessage("%1 files has been selected", FileNames.Text);
	}
}
//@ End Example

Copyright (с) Terrasoft 2002-2007.