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

 

Description

 

Body Source
//-----------------------------------------------------------------------------
// IServicesExample.js file
//-----------------------------------------------------------------------------
// There is described the usage of the IServices object in the example.
//-----------------------------------------------------------------------------
//@ Start Example

// Creating the database connection and data storage objects
var Connector = new ActiveXObject('TSDskObjectLibrary.DskConnector');
var ScriptUtils = new ActiveXObject('TSObjectLibrary.ScriptUtils');
var ServiceInfo = new ActiveXObject('TSObjectLibrary.ServiceInfo');

// 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);
}

// Flag to execute action without any confirmation 
var sdoaSave = 1;

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

	var Services = Connector.Services;

	// Displaying the information about the service quantity in the configuration
	ShowMessage("Services quantity: %1", Services.InformationsCount);

	// Reading the information about the 'enm_CustomerEnum' enomeration service
	ServiceInfo = Services.InformationsByUSI('enm_CustomerEnum');

	// Creating the service under condition it is not available in the configuration
	if (ServiceInfo == ScriptUtils.EmptyValue) {

		ShowMessage("Adding the enumeration service");

		// Creating the enumeration service and adding its items
		Enum = Services.CreateItem('Enum');
		Enum.USI = 'X15\\enm_CustomerEnum';
		Enum.Caption = "User's enumeration";
		for (i = 0; i < 5; i++) {
			EnumItem = Enum.CreateItem();
			EnumItem.ID = Connector.GenGUID();
			EnumItem.Caption = "Item caption of the enumeration #" + i;
			EnumItem.Code = "Code" + i;
			Enum.Add(EnumItem);
		}

		// Saving enumeration service to the database
		if (Services.SaveItem(Enum, sdoaSave)) {
			// Updating service information
			ShowMessage("Services quantity: %1", Services.InformationsCount);
		} else {
			ShowMessage("Enumeration service is not saved");
		}
	} else {
		// The required enumeration is already available in the database
		// Creating the service of the given enumeration
		Enum = Services.GetNewItemByUSI('enm_CustomerEnum');
	}

	// Creating the window service by the method GetSingleItemByUSI 
	// Demonstrating the profile serialization
	var EditWindow = Services.GetSingleItemByUSI('wnd_ContactEdit');
	EditWindow.Attributes('RecordID') = '';
	EditWindow.Prepare();
	ShowMessage("Change the window location and close");
	EditWindow.ShowModal();
	Services.SerializeItemToProfile(EditWindow, 'CustomerKey');

	var EditWindow = Services.GetSingleItemByUSI('wnd_ContactEdit');
	EditWindow.Attributes('RecordID') = '';
	EditWindow.Prepare();
	Services.DeserializeItemFromProfile(EditWindow, 'CustomerKey');
	EditWindow.ShowModal();

	// Removing the created enumeration
	Services.DeleteItem('X15\\enm_CustomerEnum', sdoaSave);
}
//@ End Example
Copyright (с) Terrasoft 2002-2007.