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

 

Description

 

 

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

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

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


if (Connector.Login("Example of the IEnum use")) {
     
    ShowMessage("Adding the enumeration service");
    
    // Creating the enumeration service and adding its items
    Enum = Connector.Services.CreateItem('Enum');
    Enum.USI = 'X15\\enm_CustomerEnum';
    Enum.Caption = "User's enumeration"; 
    
    // Creating the enumeration service items 
    for (i = 0; i < 5; i++) {
        EnumItem = Enum.CreateItem();
        EnumItem.ID = Connector.GenGUID();
        EnumItem.Caption = "Value #" + i;
        EnumItem.Code = 'Code' + i;
        Enum.Add(EnumItem);        
    }	
   
   // Adding the information about enumeration service
   StringsList.Add("Information about the created enumeration");
   StringsList.Add("Enumeration identifier " + Enum.ID);
   StringsList.Add("Enumeration USI" + Enum.USI);
   StringsList.Add("Caption " + Enum.Caption);
   StringsList.Add("Enumeration items");
   
   // Adding the information about enumeration service items and removing all the items
   for (i = 0; i < 5; i++) {
        EnumItem = Enum.ItemsByCaption("Value #" + i);
        StringsList.Add(EnumItem.Code + ' ' + EnumItem.Caption);
        Enum.Remove(EnumItem);        
   }	
   
   // Displaying the information about enumeration
   ShowMessage(StringsList.Text); 
}
//@ End Example

Copyright (с) Terrasoft 2002-2007.