Instantiation of the COM (eWare.CRM) object

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Instantiation of the COM (eWare.CRM) object

  • Comments 5
  • Likes
The "eWare" or "CRM" COM Object can be instantiated in variety of ways.

1) ASP main interface application extensions
2) ASP Self Service pages
3) External Applications

1) ASP main interface application extensions

For application extensions of the main User Interface using ASP pages, you would use the eware.js/accpaccrm.js include file approach that Marc mentioned earlier.

A very simple ASP page build that way looks like:


<!-- #include file ="eWare.js"--> 
<% 
var myBlock = eWare.GetBlock("caselist"); 
var intRecordId = eWare.GetContextInfo("company","comp_companyid"); 
var Arg = "case_primarycompanyid="+intRecordId; 
eWare.AddContent(myBlock.Execute(Arg)); 
Response.Write(eWare.GetPage()); 
%>


The include file does a number of things but most importantly, it instantiates the eWare object in code that looks like this:


var sInstallName = getInstallName(Request.ServerVariables("URL")); 
var ClassName = "eWare."+sInstallName; 

eWare = Server.CreateObject(ClassName); 
eMsg = eWare.Init( 
Request.Querystring, 
Request.Form, 
Request.ServerVariables("HTTPS"), 
Request.ServerVariables("SERVER_NAME"), 
false, 
Request.ServerVariables("HTTP_USER_AGENT"), 
Accept); 


2) ASP Self Service pages

The second way of instantiating the COM object is in Self Service ASP pages. The code has to be different here because the Self Service use of the objects can't use the concept of a User session. It allows authentication of visitors and also anonymous access.

The include file for Self Service pages has code that instantiates the COM object like this:


eWare = Server.CreateObject("eWare.eWareSelfService"); 
eWare.Init( 
Request.Querystring, 
Request.Form, 
Request.Cookies("eware"),true); 


3) External Applications

Another way of instantiating the COM object is in external programs and window scripts. For example you may have a js file that the windows scheduler needs to run at fixed times.

In that type of file the code looks like:


var username = "Admin"; 
var password = ""; 
var eWare = new ActiveXObject("eWare.CRM"); 
eWare.FastLogon = 3; //this prevents the meta data from loading. 
eWare.Logon(username,password); 

////////////////// 
var ForReading = 1, ForWriting = 2, ForAppending = 8; 
var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0; 
var mySystemObject = new ActiveXObject("Scripting.FileSystemObject"); 
var myFile = mySystemObject.GetFile("e:/TEST.TXT"); 
//Assumes TEST.TXT exists 
var myFileTextStream = myFile.OpenAsTextStream(ForAppending, TristateUseDefault); 
//////////////////// 
//Retrieve Record 
var myRecord = eWare.FindRecord("person","pers_gender='Male'"); 
//<!--Record Use Example --> 
while (!myRecord.eof) //eof checks for end of data and instantiates query 
{ 
myFileTextStream.WriteLine(myRecord.pers_firstname+" "+myRecord.pers_lastname); // eg. case_assigneduserid 
myRecord.NextRecord(); 
} 

myFileTextStream.Close(); 
Comments
  • Getting "Runtime error: Automation server can't create object" while excuting the javascript.

    var eWare = new ActiveXObject("eWare.CRM");

    wonder if eWare.CRM is correct in my system.how to check?

  • Is your install of Sage CRM called 'CRM'?  If your install is called CRMTest then the code would be

    var eWare = new ActiveXObject("eWare.CRMTest");

  • Can you please tell how to find the installed name for SageCRM?in registry?

  • in mine its crm only.but i'm still getting the same error on the same line

    var eWare = new ActiveXObject("eWare.CRM");

  • I was executing the script on my 64 bit windows server on 64 bit comand prompt.by running it from C:\Windows\SysWOW64\cmd.exe...it was working..