Create COM Object Method

The Create COM Object method instantiates a COM object. It returns a successful COM object or an undefined object.

Note: To allow your scripts to access the file system and run commands such as COMCreateObject, you must explicitly allow access. This is accomplished by adding these System Preferences. This does not mean you are not allowing the script to run. It means any script that calls to the file system to run commands will cause a runtime error.

Runtime Scripts System Access (default is false)

A Runtime Script is the script that you write in the Administration - Business Service Screen. Since these Business Service Methods are not compiled, they are less secure. Not all client-side Business Services need to access the file system to run commands, but if yours do, you must explicitly allow them access to the file system by adding this System Preference and setting its value to true.

Compiled Scripts System Access (default is true)

The Business Service Script that you write in Web Tools or Siebel Tools is compiled. By default these methods are allowed to access the file system and run commands such as COMCreateObject. If you want to disallow any compiled Business Service Script from accessing the file system and running commands on it you must add this System Preference and set its value to false.

Format

COMCreateObject(objectName)

The following table describes the arguments for the Create COM Object method.

Argument Description

objectName

The name of the object that this method creates.

Usage

You can configure Siebel CRM to pass any type of variable to the COM object that it calls. You must make sure the variable type is valid for the COM object. The following variable types are valid:

  • String

  • Number

  • Object pointer

Siebel CRM can run the Create COM Object method only in server script. It cannot run this method in browser script.

A DLL that the Create COM Object method instantiates must be thread-safe.

Using the Dispatch Identifier to Call a COM Method

Siebel CRM calls the method of a COM object in Siebel eScript in the same way that it calls this method in Siebel VB. In this context, a COM object is an object that the Create COM Object method instantiates.

To use the DISPID (Dispatch Identifier) of a COM method to call that COM method, you make an IDispatch::Invoke call in the COM technology. To identify methods, properties, and arguments, you use the Dispatch Identifier in the IDispatch::Invoke call.

You can write code that uses only the following arguments:

  • BSTR (basic string). An eScript string.

  • VARIANT. A universal data type.

  • SAFEARRAY. Similar to a typical C array, but also includes information about the number of elements in the array.

You cannot use Siebel eScript to call the method of a COM object that includes the LPCSTR argument for the string argument of that method. In this situation, you must use the BSTR argument.

Example

The following example instantiates Microsoft Excel as a COM object and makes it visible:

var ExcelApp = COMCreateObject("Excel.Application");
// Make Excel visible through the Application object.

ExcelApp.Visible = true;

ExcelApp.WorkBooks.Add();
// Place some text in the first cell of the sheet

ExcelApp.ActiveSheet.Cells(1,1).Value = "Column A, Row 1";
// Save the sheet

var fileName = "C:\\demo.xls";

ExcelApp.ActiveWorkbook.SaveAs (fileName);
// Close Excel with the Quit method on the Application object

ExcelApp.Application.Quit();
// Clear the object from memory

ExcelApp = null;
return (CancelOperation);

An application, such as Microsoft Excel, might change from version to version, so it might be necessary for you to modify your code to address these modifications. This example code was tested on Excel 2003.