VB.NET API: Difference between revisions

From RangerMSP Wiki - PSA software for MSPs and IT services providers
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
= Disclaimer =
= Disclaimer =


This documentation refers to CommitCRM 5.6 or later version and assumes CommitCRM is installed and accessible on the local computer.
This documentation refers to RangerMSP 5.6 or later version and assumes RangerMSP is installed and accessible on the local computer.
<br>
<br>


= Introduction =
= Introduction =


This document demonstrates how to use the CommitCRM VB.NET API library in order to programmatically connect to your CommitCRM server and query or manipulate the CommitCRM database.
This document demonstrates how to use the RangerMSP VB.NET API library in order to programmatically connect to your RangerMSP server and query or manipulate the RangerMSP database.


<br>
<br>
Line 14: Line 14:
= System Requirements =
= System Requirements =


* CommitCRM 5.6 or later.
* RangerMSP 5.6 or later.
* Visual Basic .NET 2008 or Visual Basic .NET 2010.
* Visual Basic .NET 2008 or Visual Basic .NET 2010.
* CommitLib.dll (the CommitCRM VB.NET compiled library).
* CRMLib.dll (the RangerMSP VB.NET compiled library).


= Getting Started =
= Getting Started =
Line 24: Line 24:


==Start Basic Program==
==Start Basic Program==
After you create your VB.NET project, you'll need to add a reference to the '''CommitLib.dll''' file, in order to have access to the CommitCRM library classes.
After you create your VB.NET project, you'll need to add a reference to the '''CRMLib.dll''' file, in order to have access to the RangerMSP library classes.


Each application using the library will have to initialize on startup the '''CommitCRM.Application''' object and terminate it on exit.
Each application using the library will have to initialize on startup the '''CRM.Application''' object and terminate it on exit.
Initialization method requires that you pass an object instance of '''CommitCRM.Config''' class.
Initialization method requires that you pass an object instance of '''CRM.Config''' class.


Connecting to the CommitCRM database can be done in two ways:
Connecting to the RangerMSP database can be done in two ways:
# Using a Local Server - run your program on the same server where the CommitCRM Server runs.
# Using a Local Server - run your program on the same server where the RangerMSP Server runs.
# Using Web API - run your program anywhere and connect to a remote CommitCRM server over Web services interface.
# Using Web API - run your program anywhere and connect to a remote RangerMSP server over Web services interface.


Connection parameters vary between these options. See the variations below:
Connection parameters vary between these options. See the variations below:


===Local Server===
===Local Server===
For connections to a local CommitCRM server configure the following settings:
For connections to a local RangerMSP server configure the following settings:
   
   
* '''AppName'''
* '''AppName'''
: This is free text, preferably the name of your application.
: This is free text, preferably the name of your application.
 
 
* '''CommitDllFolder'''
* '''DllFolder'''
: Behind the scenes the library uses the two CommitCRM API dlls: '''CmtDbEng.dll''' and '''CmtDbQry.dll'''.  
: Behind the scenes the library uses the two RangerMSP API dlls: '''CmtDbEng.dll''' and '''CmtDbQry.dll'''.  
: In the default CommitCRM installation you'll find these files in <span style="color: #963A46;">'C:\CommitCRM\ThirdParty\UserDev'</span>.
: In the default RangerMSP installation you'll find these files in <span style="color: #963A46;">'C:\RangerMSP\ThirdParty\UserDev'</span>.
: '''Important Note''': Always point to this folder and do '''not''' copy the dll files elsewhere. This is because when the CommitCRM version upgrade runs it also upgrades the  dll files stored in this folder. This verifies that you will always be using the latest release.
: '''Important Note''': Always point to this folder and do '''not''' copy the dll files elsewhere. This is because when the RangerMSP version upgrade runs it also upgrades the  dll files stored in this folder. This verifies that you will always be using the latest release.
   
   
* '''CommitDbFolder'''
* '''DbFolder'''
: Path to the CommitCRM database, default is <span style="color: #963A46;">'C:\CommitCRM\db'</span>.
: Path to the RangerMSP database, default is <span style="color: #963A46;">'C:\RangerMSP\db'</span>.
   
   
Assuming these default values, we can configure the '''CommitCRM.Config''' object like this:
Assuming these default values, we can configure the '''CRM.Config''' object like this:
<font face="courier new" size="3">
<font face="courier new" size="3">
   
   
  <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CommitCRM.Config
  <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CRM.Config
  config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
  config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
  config.CommitDllFolder = <span style="color: #963A46;">"C:\CommitCRM\ThirdParty\UserDev"</span>
  config.DllFolder = <span style="color: #963A46;">"C:\RangerMSP\ThirdParty\UserDev"</span>
  config.CommitDbFolder = <span style="color: #963A46;">"C:\CommitCRM\db"</span>
  config.DbFolder = <span style="color: #963A46;">"C:\RangerMSP\db"</span>
</font>
</font>
   
   
Line 61: Line 61:
   
   
===Remote Server (Web API)===
===Remote Server (Web API)===
To connect to a remote CommitCRM server with the Web API, configure the following settings:
To connect to a remote RangerMSP server with the Web API, configure the following settings:
   
   
* '''AppName'''
* '''AppName'''
Line 67: Line 67:
 
 
* '''WebAPIUrl'''
* '''WebAPIUrl'''
: Url to the CommitCRM server running the Web API, either local or remote. <br>Url '''must include''' the http:// or https:// prefix, otherwise the API will not be able to connect.<br>Valid examples include http://localhost:4964/ and https://webapi.mycommitcrmserver.com/.
: Url to the RangerMSP server running the Web API, either local or remote. <br>Url '''must include''' the http:// or https:// prefix, otherwise the API will not be able to connect.<br>Valid examples include http://localhost:4964/ and https://webapi.mycrmserver.com/.
 
 
* '''Password'''
* '''Password'''
Line 75: Line 75:
: Boolean value, must be set to True to use the Web API
: Boolean value, must be set to True to use the Web API


Assuming these default values, we can configure the '''CommitCRM.Config''' object like this:
Assuming these default values, we can configure the '''CRM.Config''' object like this:
<font face="courier new" size="3">
<font face="courier new" size="3">
   
   
  <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CommitCRM.Config
  <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CRM.Config
  config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
  config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
  config.WebAPIUrl = <span style="color: #963A46;">"http://localhost:4964/"</span>
  config.WebAPIUrl = <span style="color: #963A46;">"http://localhost:4964/"</span>
Line 86: Line 86:


===Initialization===
===Initialization===
The configuration settings explained above are the only differences between connecting to a local CommitCRM server or remote CommitCRM server running the Web API.
The configuration settings explained above are the only differences between connecting to a local RangerMSP server or remote RangerMSP server running the Web API.


Now we can initialize the '''CommitCRM.Application''' object with these settings:
Now we can initialize the '''CRM.Application''' object with these settings:
   
   
<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #66AD3A;">'CommitCRM.Application.Initialize must be the first call before invoking any other CommitCRM library method
  <span style="color: #66AD3A;">'CRM.Application.Initialize must be the first call before invoking any other RangerMSP library method
  'and it should be done <span style="color: #963A46;">only once</span> in the program's lifetime.</span>
  'and it should be done <span style="color: #963A46;">only once</span> in the program's lifetime.</span>
  CommitCRM.Application.Initialize(config)
  CRM.Application.Initialize(config)
</font>
</font>
   
   
If anything goes wrong, the above line will throw an exception of the '''CommitCRM.Exception''' class.  
If anything goes wrong, the above line will throw an exception of the '''CRM.Exception''' class.  
To prevent unexpected termination of the program execution, we recommend having any call to the CommitCRM library enclosed in a '''Try/Catch''' block.
To prevent unexpected termination of the program execution, we recommend having any call to the RangerMSP library enclosed in a '''Try/Catch''' block.
   
   
Before exit, we terminate the '''CommitCRM.Application''' object:
Before exit, we terminate the '''CRM.Application''' object:
   
   
<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #66AD3A;">'Before exit we should call CommitCRM.Application.Terminate to gracefully release all application resources
  <span style="color: #66AD3A;">'Before exit we should call CRM.Application.Terminate to gracefully release all application resources
  'and this should be done <span style="color: #963A46;">only once</span> in the program's lifetime.</span>
  'and this should be done <span style="color: #963A46;">only once</span> in the program's lifetime.</span>
  CommitCRM.Application.Terminate()
  CRM.Application.Terminate()
</font>
</font>


The most basic VB.NET application that just connects to CommitCRM and terminates could look something like this:
The most basic VB.NET application that just connects to RangerMSP and terminates could look something like this:
   
   
<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Try</span>
  <span style="color: #3A3AFF;">Try</span>
     <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CommitCRM.Config
     <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CRM.Config
     config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
     config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
     config.CommitDllFolder = <span style="color: #963A46;">"C:\CommitCRM\ThirdParty\UserDev"</span>
     config.DllFolder = <span style="color: #963A46;">"C:\RangerMSP\ThirdParty\UserDev"</span>
     config.CommitDbFolder = <span style="color: #963A46;">"C:\CommitCRM\db"</span>
     config.DbFolder = <span style="color: #963A46;">"C:\RangerMSP\db"</span>
   
   
     CommitCRM.Application.Initialize(config)
     CRM.Application.Initialize(config)
   
   
     <span style="color: #66AD3A;">'At this point we have successfully initialized the CommitCRM.Application
     <span style="color: #66AD3A;">'At this point we have successfully initialized the CRM.Application
     'and can start using the other library classes</span>
     'and can start using the other library classes</span>
  <span style="color: #3A3AFF;">Catch</span> ex <span style="color: #3A3AFF;">As</span> Exception  
  <span style="color: #3A3AFF;">Catch</span> ex <span style="color: #3A3AFF;">As</span> Exception  
     Console.Out.Write(ex.Message)
     Console.Out.Write(ex.Message)
  <span style="color: #3A3AFF;">Finally</span>
  <span style="color: #3A3AFF;">Finally</span>
     CommitCRM.Application.Terminate()
     CRM.Application.Terminate()
  <span style="color: #3A3AFF;">End Try</span>
  <span style="color: #3A3AFF;">End Try</span>
</font>
</font>
Now that we have confirmed the connectivity to the CommitCRM server (if the above code successfully runs),
Now that we have confirmed the connectivity to the RangerMSP server (if the above code successfully runs),
we can continue adding more functionality to the example.
we can continue adding more functionality to the example.
   
   
The library exposes as VB.NET classes the same CommitCRM objects (Account, Ticket etc.) available through the native CommitCRM API and you can refer to the  
The library exposes as VB.NET classes the same RangerMSP objects (Account, Ticket etc.) available through the native RangerMSP API and you can refer to the  
[[API_Reference_Manual#Database_Field_Listing|API Reference Manual]] for database fields reference.
[[API_Reference_Manual#Database_Field_Listing|API Reference Manual]] for database fields reference.
   
   
Line 135: Line 135:
With any of these objects you can:
With any of these objects you can:
   
   
* Search and query for objects with '''CommitCRM.ObjectQuery''' that satisfy certain criteria.
* Search and query for objects with '''CRM.ObjectQuery''' that satisfy certain criteria.
* Read and display the properties of the retrieved objects.
* Read and display the properties of the retrieved objects.
* Update and save the properties of the retrieved objects.
* Update and save the properties of the retrieved objects.
Line 141: Line 141:
   
   
   
   
Now let's see how we can search for '''CommitCRM.Account''' objects.
Now let's see how we can search for '''CRM.Account''' objects.
We instantiate an object of the '''CommitCRM.ObjectQuery''' class and pass '''CommitCRM.Account''' class as generics parameter.
We instantiate an object of the '''CRM.ObjectQuery''' class and pass '''CRM.Account''' class as generics parameter.
<font face="courier new" size="3">
<font face="courier new" size="3">
   
   
  <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CommitCRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account)
  <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CRM.Account)
</font>
</font>
   
   
'''CommitCRM.ObjectQuery''' class can accept any of the CommitCRM objects in this parameter, but we want to search for accounts now.
'''CRM.ObjectQuery''' class can accept any of the RangerMSP objects in this parameter, but we want to search for accounts now.
   
   


Next, we need to set criteria (or more than one) we want to search for:
Next, we need to set criteria (or more than one) we want to search for:
<font face="courier new" size="3">
<font face="courier new" size="3">
  accountSearch.AddCriteria(CommitCRM.Ticket.Fields.City, CommitCRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
  accountSearch.AddCriteria(CRM.Ticket.Fields.City, CRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
</font>
</font>
   
   
The first parameter to the '''AddCriteria''' method is either a Shared object instance of '''CommitCRM.CmtField''' class representing the field we want to look in or the internal API field name. Refer to the '''API Field Name''' column in the [[VB.NET_API#Account_Class|Account Class]]  
The first parameter to the '''AddCriteria''' method is either a Shared object instance of '''CRM.CrmField''' class representing the field we want to look in or the internal API field name. Refer to the '''API Field Name''' column in the [[VB.NET_API#Account_Class|Account Class]]  
table for a complete list of the available fields for the '''CommitCRM.Account''' class.
table for a complete list of the available fields for the '''CRM.Account''' class.
   
   
The second parameter is a compare operator. We here use the '''CommitCRM.OperatorEnum.opEqual''' to get only exact matches.
The second parameter is a compare operator. We here use the '''CRM.OperatorEnum.opEqual''' to get only exact matches.
In order to get a broader match in the results you can use '''CommitCRM.OperatorEnum.opLike''' operator.
In order to get a broader match in the results you can use '''CRM.OperatorEnum.opLike''' operator.
   
   
The third parameter is the value we want to find. Prepending and/or appending % (percent) sign at the beginning and/or at the end while using '''CommitCRM.OperatorEnum.opLike''' operator,  
The third parameter is the value we want to find. Prepending and/or appending % (percent) sign at the beginning and/or at the end while using '''CRM.OperatorEnum.opLike''' operator,  
will match the phrase even if in the middle of a sentence.
will match the phrase even if in the middle of a sentence.
   
   
Now we can execute the search and retrieve the '''CommitCRM.Account''' objects (if any):
Now we can execute the search and retrieve the '''CRM.Account''' objects (if any):
   
   
<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account) = accountSearch.FetchObjects()
  <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CRM.Account) = accountSearch.FetchObjects()
</font>
</font>
   
   
The above line will populate the List ('''System.Collections.Generic.List''') with all '''CommitCRM.Account''' objects that were found.
The above line will populate the List ('''System.Collections.Generic.List''') with all '''CRM.Account''' objects that were found.
Now we can use '''For Each - Next''' statement to iterate through the accounts:
Now we can use '''For Each - Next''' statement to iterate through the accounts:
   
   
Line 191: Line 191:
</font>
</font>
   
   
We invoke the '''CommitCRM.Account's''' Save method on both new or existing accounts. For a new account, invoking the Save method would insert a new account in the CommitCRM database.
We invoke the '''CRM.Account's''' Save method on both new or existing accounts. For a new account, invoking the Save method would insert a new account in the RangerMSP database.
For an existing account, invoking the Save method would update the fields we modified in the existing account. This rule applies to all CommitCRM objects.
For an existing account, invoking the Save method would update the fields we modified in the existing account. This rule applies to all RangerMSP objects.
   
   
Another option is to add a new ticket for each of the accounts:
Another option is to add a new ticket for each of the accounts:
Line 198: Line 198:
<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">For Each</span> account <span style="color: #3A3AFF;">In</span> accounts
  <span style="color: #3A3AFF;">For Each</span> account <span style="color: #3A3AFF;">In</span> accounts
     <span style="color: #3A3AFF;">Dim</span> ticket <span style="color: #3A3AFF;">As New</span> CommitCRM.Ticket
     <span style="color: #3A3AFF;">Dim</span> ticket <span style="color: #3A3AFF;">As New</span> CRM.Ticket
     ticket.AccountREC_ID = account.AccountREC_ID
     ticket.AccountREC_ID = account.AccountREC_ID
     ticket.Description = <span style="color: #963A46;">"Sample ticket for a NewYork account"</span>
     ticket.Description = <span style="color: #963A46;">"Sample ticket for a NewYork account"</span>
Line 207: Line 207:
= GetFieldValue and SetFieldValue methods =
= GetFieldValue and SetFieldValue methods =


Each of the CommitCRM library objects have a set of properties that are exposed as VB.NET properties that you can directly manipulate or read from.
Each of the RangerMSP library objects have a set of properties that are exposed as VB.NET properties that you can directly manipulate or read from.
You already saw few examples of these properties in the above examples, as: '''account.Zip''' or '''ticket.Description'''. This is the preferred and more intuitive way of accessing the CommitCRM fields.
You already saw few examples of these properties in the above examples, as: '''account.Zip''' or '''ticket.Description'''. This is the preferred and more intuitive way of accessing the RangerMSP fields.


<br>However, there is also another way of achieving the same results, by invoking '''GetFieldValue''' and '''SetFieldValue''' and specifying the internal field name. These methods should only be used if necessary, for example, when updating user-defined custom fields which are not part of the class predefined basic fields.  
<br>However, there is also another way of achieving the same results, by invoking '''GetFieldValue''' and '''SetFieldValue''' and specifying the internal field name. These methods should only be used if necessary, for example, when updating user-defined custom fields which are not part of the class predefined basic fields.  
Line 216: Line 216:
<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">For Each</span> account <span style="color: #3A3AFF;">In</span> accounts
  <span style="color: #3A3AFF;">For Each</span> account <span style="color: #3A3AFF;">In</span> accounts
     <span style="color: #3A3AFF;">Dim</span> ticket <span style="color: #3A3AFF;">As New</span> CommitCRM.Ticket
     <span style="color: #3A3AFF;">Dim</span> ticket <span style="color: #3A3AFF;">As New</span> CRM.Ticket
     ticket.SetFieldValue(<span style="color: #963A46;">"FLDTKTCARDID"</span>, account.GetFieldValue(<span style="color: #963A46;">"FLDCRDRECID"</span>))
     ticket.SetFieldValue(<span style="color: #963A46;">"FLDTKTCARDID"</span>, account.GetFieldValue(<span style="color: #963A46;">"FLDCRDRECID"</span>))
     ticket.SetFieldValue(<span style="color: #963A46;">"FLDTKTPROBLEM"</span>, <span style="color: #963A46;">"Sample ticket for a NewYork account"</span>)
     ticket.SetFieldValue(<span style="color: #963A46;">"FLDTKTPROBLEM"</span>, <span style="color: #963A46;">"Sample ticket for a NewYork account"</span>)
Line 227: Line 227:
= Exception Handling =
= Exception Handling =
   
   
While working with the CommitCRM VB.NET library, some operations can fail. In this case the library will throw an exception of the '''CommitCRM.Exception''' class.
While working with the RangerMSP VB.NET library, some operations can fail. In this case the library will throw an exception of the '''CRM.Exception''' class.
We recommend enclosing all calls to the CommitCRM library in a '''Try/Catch''' block.
We recommend enclosing all calls to the RangerMSP library in a '''Try/Catch''' block.


To find out more about the exact error that ocured when an exception is thrown, you can inspect the '''CommitCRM.Exception.Status''' property that holds the last CommitCRM '''Status''' value,
To find out more about the exact error that ocured when an exception is thrown, you can inspect the '''CRM.Exception.Status''' property that holds the last RangerMSP '''Status''' value,
or inspect the list of '''CommitCRM.Exception.Codes''' (if any). Please refer to [[API_Reference_Manual#Error_Codes_Description|Error Codes Description]] for the description of these values.
or inspect the list of '''CRM.Exception.Codes''' (if any). Please refer to [[API_Reference_Manual#Error_Codes_Description|Error Codes Description]] for the description of these values.


= Complete Program Sample =
= Complete Program Sample =
Line 241: Line 241:
   
   
         <span style="color: #3A3AFF;">Try</span>
         <span style="color: #3A3AFF;">Try</span>
             <span style="color: #66AD3A;">'Setup the CommitCRM.Config object</span>
             <span style="color: #66AD3A;">'Setup the CRM.Config object</span>
             <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CommitCRM.Config
             <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CRM.Config
             config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
             config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
             config.CommitDllFolder = <span style="color: #963A46;">"C:\CommitCRM\ThirdParty\UserDev"</span>
             config.DllFolder = <span style="color: #963A46;">"C:\RangerMSP\ThirdParty\UserDev"</span>
             config.CommitDbFolder = <span style="color: #963A46;">"C:\CommitCRM\db"</span>
             config.DbFolder = <span style="color: #963A46;">"C:\RangerMSP\db"</span>
   
   
             <span style="color: #66AD3A;">'Initialize the CommitCRM.Application</span>
             <span style="color: #66AD3A;">'Initialize the CRM.Application</span>
             CommitCRM.Application.Initialize(config)
             CRM.Application.Initialize(config)
   
   
             <span style="color: #66AD3A;">'At this point we have successfully initialized the CommitCRM.Application
             <span style="color: #66AD3A;">'At this point we have successfully initialized the CRM.Application
             'and can start using the other library classes</span>
             'and can start using the other library classes</span>
   
   
             <span style="color: #66AD3A;">'search for "New York" in the FLDCRDCITY field</span>
             <span style="color: #66AD3A;">'search for "New York" in the FLDCRDCITY field</span>
             <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CommitCRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account)
             <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CRM.Account)
             accountSearch.AddCriteria(<span style="color: #963A46;">"FLDCRDCITY"</span>, CommitCRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
             accountSearch.AddCriteria(<span style="color: #963A46;">"FLDCRDCITY"</span>, CRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
             <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account) = accountSearch.FetchObjects()
             <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CRM.Account) = accountSearch.FetchObjects()
   
   
             <span style="color: #66AD3A;">'loop through the retrieved accounts and output the CompanyName</span>
             <span style="color: #66AD3A;">'loop through the retrieved accounts and output the CompanyName</span>
Line 263: Line 263:
             <span style="color: #3A3AFF;">Next</span>
             <span style="color: #3A3AFF;">Next</span>
   
   
         <span style="color: #3A3AFF;">Catch</span> ex <span style="color: #3A3AFF;">As</span> CommitCRM.Exception <span style="color: #66AD3A;">'here we catch CommitCRM specific error
         <span style="color: #3A3AFF;">Catch</span> ex <span style="color: #3A3AFF;">As</span> CRM.Exception <span style="color: #66AD3A;">'here we catch RangerMSP specific error
             'we can inspect the Commit status (exc.Status)  
             'we can inspect the RangerMSP status (exc.Status)  
             'exc.Codes contains all error codes last call generated
             'exc.Codes contains all error codes last call generated
   
   
Line 273: Line 273:
             Console.Out.Write(ex.Message)
             Console.Out.Write(ex.Message)
         <span style="color: #3A3AFF;">Finally</span>
         <span style="color: #3A3AFF;">Finally</span>
             CommitCRM.Application.Terminate()
             CRM.Application.Terminate()
         <span style="color: #3A3AFF;">End Try</span>
         <span style="color: #3A3AFF;">End Try</span>
     <span style="color: #3A3AFF;">End Sub</span>
     <span style="color: #3A3AFF;">End Sub</span>
Line 281: Line 281:


= Classes and Objects =
= Classes and Objects =
The CommitCRM VB.NET API provides easy access to all objects using a class for each entity in the system (such as Account, Ticket, Asset, etc.).  
The RangerMSP VB.NET API provides easy access to all objects using a class for each entity in the system (such as Account, Ticket, Asset, etc.).  


All classes include:
All classes include:
# API functions and routines (which are derived from the base '''CommitCRM.Object''' class).  
# API functions and routines (which are derived from the base '''CRM.Object''' class).  
# Class data fields, providing an easy way to update the object's data.
# Class data fields, providing an easy way to update the object's data.


<br>
<br>
All CommitCRM's objects should be updated by setting the class data fields (properties) and then calling the '''Save''' method. For example, to create a new account programmatically (assuming CommitCRM.Application was initialized successfully), one would use the following code snippet:
All RangerMSP's objects should be updated by setting the class data fields (properties) and then calling the '''Save''' method. For example, to create a new account programmatically (assuming CRM.Application was initialized successfully), one would use the following code snippet:


<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Dim</span> account <span style="color: #3A3AFF;">As New</span> CommitCRM.Account
  <span style="color: #3A3AFF;">Dim</span> account <span style="color: #3A3AFF;">As New</span> CRM.Account
  account.FileAs = <span style="color: #963A46;">"ACME Company"</span>
  account.FileAs = <span style="color: #963A46;">"ACME Company"</span>
  account.Dear = <span style="color: #963A46;">"Mr."</span>
  account.Dear = <span style="color: #963A46;">"Mr."</span>
Line 303: Line 303:
== Object Class ==
== Object Class ==


The '''CommitCRM.Object''' class is the base class for all CommitCRM accessible objects (as Ticket, Account, Asset, etc.). The public routines and functions exposed by the CommitCRM.Object class are available to the derived classes.
The '''CRM.Object''' class is the base class for all RangerMSP accessible objects (as Ticket, Account, Asset, etc.). The public routines and functions exposed by the CRM.Object class are available to the derived classes.
<br><br>
<br><br>
'''Object Method Reference Table'''
'''Object Method Reference Table'''
Line 347: Line 347:
== Object derived classes ==
== Object derived classes ==


Classes explained in this section are derived from '''CommitCRM.Object''' class and map directly to a native CommitCRM object (Account, Ticket, etc.).
Classes explained in this section are derived from '''CRM.Object''' class and map directly to a native RangerMSP object (Account, Ticket, etc.).


=== Account Class ===
=== Account Class ===


The '''CommitCRM.Account''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Account_Fields|Account Fields]].
The '''CRM.Account''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Account_Fields|Account Fields]].
The following table lists all exposed '''CommitCRM.Account''' properties.
The following table lists all exposed '''CRM.Account''' properties.


'''Account Properties Reference Table'''
'''Account Properties Reference Table'''
Line 696: Line 696:
=== Ticket Class ===
=== Ticket Class ===


The '''CommitCRM.Ticket''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Ticket_Fields|Ticket Fields]].
The '''CRM.Ticket''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Ticket_Fields|Ticket Fields]].
The following table lists all exposed '''CommitCRM.Ticket''' properties.
The following table lists all exposed '''CRM.Ticket''' properties.


'''Ticket Properties Reference Table'''
'''Ticket Properties Reference Table'''
Line 819: Line 819:
=== Asset Class ===
=== Asset Class ===


The '''CommitCRM.Asset''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Asset_Fields|Asset Fields]].
The '''CRM.Asset''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Asset_Fields|Asset Fields]].
The following table lists all exposed '''CommitCRM.Asset''' properties.
The following table lists all exposed '''CRM.Asset''' properties.


'''Asset Properties Reference Table'''  
'''Asset Properties Reference Table'''  
Line 1,098: Line 1,098:
=== Calendar Class ===
=== Calendar Class ===


The '''CommitCRM.Calendar''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Calendar_Fields|Calendar Fields]] of event type Appointment.
The '''CRM.Calendar''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Calendar_Fields|Calendar Fields]] of event type Appointment.
The following table lists all exposed '''CommitCRM.Calendar''' properties.
The following table lists all exposed '''CRM.Calendar''' properties.


'''Calendar Properties Reference Table'''
'''Calendar Properties Reference Table'''
Line 1,233: Line 1,233:
=== Task Class ===
=== Task Class ===


The '''CommitCRM.Task''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Calendar_Fields|Calendar Fields]] of event type Task.
The '''CRM.Task''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Calendar_Fields|Calendar Fields]] of event type Task.
The following table lists all exposed '''CommitCRM.Task''' properties.
The following table lists all exposed '''CRM.Task''' properties.


'''Task Properties Reference Table'''
'''Task Properties Reference Table'''
Line 1,362: Line 1,362:
=== Charge Class ===
=== Charge Class ===


The '''CommitCRM.Charge''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Charge_Fields|Charge Fields]].
The '''CRM.Charge''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Charge_Fields|Charge Fields]].
The following table lists all exposed '''CommitCRM.Charge''' properties.
The following table lists all exposed '''CRM.Charge''' properties.


'''Charge Properties Reference Table'''
'''Charge Properties Reference Table'''
Line 1,497: Line 1,497:
=== Quote Class ===
=== Quote Class ===


The '''CommitCRM.Quote''' class derives from '''CommitCRM.Object'''. The following table lists all exposed '''CommitCRM.Quote''' properties.
The '''CRM.Quote''' class derives from '''CRM.Object'''. The following table lists all exposed '''CRM.Quote''' properties.


'''Quote Properties Reference Table'''
'''Quote Properties Reference Table'''
Line 1,758: Line 1,758:
=== QuoteLine Class ===
=== QuoteLine Class ===


The '''CommitCRM.QuoteLine''' class derives from '''CommitCRM.Object'''. The following table lists all exposed '''CommitCRM.QuoteLine''' properties.
The '''CRM.QuoteLine''' class derives from '''CRM.Object'''. The following table lists all exposed '''CRM.QuoteLine''' properties.


'''QuoteLine Properties Reference Table'''
'''QuoteLine Properties Reference Table'''
Line 1,960: Line 1,960:
=== Document Class ===
=== Document Class ===


The '''CommitCRM.Document''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Document_Fields|Document Fields]].
The '''CRM.Document''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Document_Fields|Document Fields]].
The following table lists all exposed '''CommitCRM.Document''' properties.
The following table lists all exposed '''CRM.Document''' properties.


'''Document Properties Reference Table'''
'''Document Properties Reference Table'''
Line 2,059: Line 2,059:
=== HistoryNote Class ===
=== HistoryNote Class ===


The '''CommitCRM.HistoryNote''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#History_Note_Fields|History Note Fields]].
The '''CRM.HistoryNote''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#History_Note_Fields|History Note Fields]].
The following table lists all exposed '''CommitCRM.HistoryNote''' properties.
The following table lists all exposed '''CRM.HistoryNote''' properties.


'''HistoryNote Properties Reference Table'''
'''HistoryNote Properties Reference Table'''
Line 2,140: Line 2,140:
=== Item Class ===
=== Item Class ===


The '''CommitCRM.Item''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Item_Fields|Item Fields]].
The '''CRM.Item''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Item_Fields|Item Fields]].
The following table lists all exposed '''CommitCRM.Item''' properties.
The following table lists all exposed '''CRM.Item''' properties.


'''Item Properties Reference Table'''  
'''Item Properties Reference Table'''  
Line 2,257: Line 2,257:
=== KnowledgeBaseArticle Class ===
=== KnowledgeBaseArticle Class ===


The '''CommitCRM.KnowledgeBaseArticle''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Knowledge_Base_Article_Fields|Knowledge Base Article Fields]].
The '''CRM.KnowledgeBaseArticle''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Knowledge_Base_Article_Fields|Knowledge Base Article Fields]].
The following table lists all exposed '''CommitCRM.KnowledgeBaseArticle''' properties.
The following table lists all exposed '''CRM.KnowledgeBaseArticle''' properties.


'''KnowledgeBaseArticle Properties Reference Table'''
'''KnowledgeBaseArticle Properties Reference Table'''
Line 2,332: Line 2,332:
=== Opportunity Class ===
=== Opportunity Class ===


The '''CommitCRM.Opportunity''' class derives from '''CommitCRM.Object''' and encapsulates the [[API_Reference_Manual#Opportunity_Fields|Opportunity Fields]].
The '''CRM.Opportunity''' class derives from '''CRM.Object''' and encapsulates the [[API_Reference_Manual#Opportunity_Fields|Opportunity Fields]].
The following table lists all exposed '''CommitCRM.Opportunity''' properties.
The following table lists all exposed '''CRM.Opportunity''' properties.


'''Opportunity Properties Reference Table'''
'''Opportunity Properties Reference Table'''
Line 2,491: Line 2,491:
=== Contact Class ===
=== Contact Class ===


The '''CommitCRM.Contact''' class derives from '''CommitCRM.Object''' and it represents the secondary contacts to a '''CommitCRM.Account'''.
The '''CRM.Contact''' class derives from '''CRM.Object''' and it represents the secondary contacts to a '''CRM.Account'''.
The following table lists all exposed '''CommitCRM.Contact''' properties.
The following table lists all exposed '''CRM.Contact''' properties.


'''Contact Properties Reference Table'''
'''Contact Properties Reference Table'''
Line 2,685: Line 2,685:
== Config Class ==
== Config Class ==


'''CommitCRM.Config''' class is used to pass the global configuration settings to the '''CommitCRM.Application Initialize''' method.
'''CRM.Config''' class is used to pass the global configuration settings to the '''CRM.Application Initialize''' method.


{| class="wikitable"
{| class="wikitable"
Line 2,699: Line 2,699:
| Maximum 15 chars, string that best identifies your application.
| Maximum 15 chars, string that best identifies your application.
|-
|-
| '''CommitDllFolder'''
| '''DllFolder'''
| String
| String
| '''Yes'''
| '''Yes'''
| Exact path to the folder where CommitCRM API DLLs are located ('''CmtDbEng.dll''' and '''CmtDbQry.dll''', usually '''"C:\CommitCRM\ThirdParty\UserDev"''').
| Exact path to the folder where RangerMSP API DLLs are located ('''CmtDbEng.dll''' and '''CmtDbQry.dll''', usually '''"C:\RangerMSP\ThirdParty\UserDev"''').
|-
|-
| '''CommitDbFolder'''
| '''DbFolder'''
| String
| String
| '''Yes'''
| '''Yes'''
| Exact path to the folder where CommitCRM database is located (usually '''"C:\CommitCRM\db"''').
| Exact path to the folder where RangerMSP database is located (usually '''"C:\RangerMSP\db"''').
|-
|-
| '''InitCommitApiDll'''
| '''InitCRMApiDll'''
| Boolean
| Boolean
| No
| No
| Initializes the '''CmtDbEng.dll''' file, which is required for proper functioning of all update functions. True by default (recommended setting). Set it to False only if you know what you are doing.
| Initializes the '''CmtDbEng.dll''' file, which is required for proper functioning of all update functions. True by default (recommended setting). Set it to False only if you know what you are doing.
|-
|-
| '''InitCommitQryDll'''
| '''InitCRMQryDll'''
| Boolean
| Boolean
| No
| No
Line 2,732: Line 2,732:
== Application Class ==
== Application Class ==


The CommitCRM.Application class implements a [http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern] that hold all global defined application settings and is used for easy access to these settings. Once the main CommitCRM.Application object is initialized, you can refer to this instance by writing: CommitCRM.Application.instance().
The CRM.Application class implements a [http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern] that hold all global defined application settings and is used for easy access to these settings. Once the main CRM.Application object is initialized, you can refer to this instance by writing: CRM.Application.instance().


Table below lists the CommitCRM.Application properties.
Table below lists the CRM.Application properties.


{| class="wikitable"
{| class="wikitable"
Line 2,744: Line 2,744:
| '''config'''
| '''config'''
| Config
| Config
| Access to the CommitCRM.Config object passed in CommitCRM.Application.Initialize method.
| Access to the CRM.Config object passed in CRM.Application.Initialize method.
|-
|-
| '''CmtDateFormat'''
| '''CmtDateFormat'''
| String
| String
| Global CommitCRM date format (as dd/mm/yyyy or mm/dd/yyyy). You'll need to refer to this setting if you are directly manipulating DateTime field (using SetFieldValue method).
| Global RangerMSP date format (as dd/mm/yyyy or mm/dd/yyyy). You'll need to refer to this setting if you are directly manipulating DateTime field (using SetFieldValue method).
|-
|-
| '''CmtDateSeparator'''
| '''CmtDateSeparator'''
Line 2,756: Line 2,756:
| '''CmtTimeFormat'''
| '''CmtTimeFormat'''
| String
| String
| Global CommitCRM time format.
| Global RangerMSP time format.
|-
|-
| '''CmtIsTimeFormatAMPMInUse'''
| '''CmtIsTimeFormatAMPMInUse'''
Line 2,763: Line 2,763:
|}
|}


Table below list the CommitCRM.Application methods.
Table below list the CRM.Application methods.


{| class="wikitable"
{| class="wikitable"
Line 2,777: Line 2,777:
| ()
| ()
| Application
| Application
| Method that returns the singleton object. Use it to access all CommitCRM.Application properties/methods.
| Method that returns the singleton object. Use it to access all CRM.Application properties/methods.
|-
|-
| Public Shared Sub
| Public Shared Sub
Line 2,783: Line 2,783:
| (ByVal c As Config)
| (ByVal c As Config)
|
|
| Method that initializes the internal CommitCRM API DLLs. Must be the first call before using any other CommitCRM library calls.
| Method that initializes the internal RangerMSP API DLLs. Must be the first call before using any other RangerMSP library calls.
|-
|-
| Public Shared Sub
| Public Shared Sub
Line 2,789: Line 2,789:
| ()
| ()
|  
|  
| Terminates all CommitCRM internal resources. You should call this method before exit from your application.
| Terminates all RangerMSP internal resources. You should call this method before exit from your application.
|}
|}


== CmtField Class ==
== CrmField Class ==


The '''CommitCRM.CmtField''' class holds the basic attributes for each database field. For each of the classes that represent CommitCRM objects (Account, Ticket, etc.) there is a preinitialized set of shared '''CommitCRM.CmtField''' objects that correspond to the properties defined for the class. For example, the '''CommitCRM.Account''' class has a property '''FileAs''' ('''CommitCRM.Account.FileAs'''). To this property corresponds one shared object instance of the '''CommitCRM.CmtField''' class accessible through '''CommitCRM.Account.Fields.FileAs'''. To the property '''LastName''' ('''CommitCRM.Account.LastName'''), corresponds the shared object '''CommitCRM.Account.Fields.LastName''' of type '''CommitCRM.CmtField'''. And so on, for each property in each class.
The '''CRM.CrmField''' class holds the basic attributes for each database field. For each of the classes that represent RangerMSP objects (Account, Ticket, etc.) there is a preinitialized set of shared '''CRM.CrmField''' objects that correspond to the properties defined for the class. For example, the '''CRM.Account''' class has a property '''FileAs''' ('''CRM.Account.FileAs'''). To this property corresponds one shared object instance of the '''CRM.CrmField''' class accessible through '''CRM.Account.Fields.FileAs'''. To the property '''LastName''' ('''CRM.Account.LastName'''), corresponds the shared object '''CRM.Account.Fields.LastName''' of type '''CRM.CrmField'''. And so on, for each property in each class.


Below is a table that lists the properties available in the '''CommitCRM.CmtField''' class.
Below is a table that lists the properties available in the '''CRM.CrmField''' class.


{| class="wikitable"
{| class="wikitable"
Line 2,840: Line 2,840:


<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #66AD3A;">'charge is of type '''CommitCRM.Charge''' and is previously initialized</span>
  <span style="color: #66AD3A;">'charge is of type '''CRM.Charge''' and is previously initialized</span>
  Console.Out.Write(charge.AdjustAmount.ToString() + CommitCRM.Charge.Fields.AdjustAmount.DisplaySymbol)
  Console.Out.Write(charge.AdjustAmount.ToString() + CRM.Charge.Fields.AdjustAmount.DisplaySymbol)
</font>
</font>


== ObjectQuery Class ==
== ObjectQuery Class ==


'''CommitCRM.ObjectQuery''' is a generics class that can operate with any of the '''CommitCRM.Object''' derived classes. It is used to query for objects of certain type (Account, Ticket, etc.). For example, the following code snippet searches for all tickets of an account updated since certain date:
'''CRM.ObjectQuery''' is a generics class that can operate with any of the '''CRM.Object''' derived classes. It is used to query for objects of certain type (Account, Ticket, etc.). For example, the following code snippet searches for all tickets of an account updated since certain date:


<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Dim</span> ticketSearch <span style="color: #3A3AFF;">As New</span> CommitCRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CommitCRM.Ticket)
  <span style="color: #3A3AFF;">Dim</span> ticketSearch <span style="color: #3A3AFF;">As New</span> CRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CRM.Ticket)
  <span style="color: #66AD3A;">'account is previously initialized</span>
  <span style="color: #66AD3A;">'account is previously initialized</span>
  ticketSearch.AddCriteria(CommitCRM.Ticket.Fields.AccountREC_ID, CommitCRM.OperatorEnum.opEqual, account.AccountREC_ID)
  ticketSearch.AddCriteria(CRM.Ticket.Fields.AccountREC_ID, CRM.OperatorEnum.opEqual, account.AccountREC_ID)
  ticketSearch.AddCriteria(CommitCRM.Ticket.Fields.UpdateDate, CommitCRM.OperatorEnum.opGreaterThanOrEqual, DateTime.Parse(<span style="color: #963A46;">"01 Jan 2011"</span>))
  ticketSearch.AddCriteria(CRM.Ticket.Fields.UpdateDate, CRM.OperatorEnum.opGreaterThanOrEqual, DateTime.Parse(<span style="color: #963A46;">"01 Jan 2011"</span>))
  <span style="color: #3A3AFF;">Dim</span> tickets <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CommitCRM.Ticket) = ticketSearch.FetchObjects()
  <span style="color: #3A3AFF;">Dim</span> tickets <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CRM.Ticket) = ticketSearch.FetchObjects()
  <span style="color: #66AD3A;">'tickets now contains all CommitCRM.Ticket objects that satisfy the above criteria.</span>
  <span style="color: #66AD3A;">'tickets now contains all CRM.Ticket objects that satisfy the above criteria.</span>
</font>
</font>


By default, '''CommitCRM.ObjectQuery.AddCriteria''' method uses the logical AND operator to link the conditions. Thus, in case more than one condition are added, all have to be satisfied in order for an object to get into the search results.
By default, '''CRM.ObjectQuery.AddCriteria''' method uses the logical AND operator to link the conditions. Thus, in case more than one condition are added, all have to be satisfied in order for an object to get into the search results.


In case we want to search for objects and it is enough to satisfy any of the criteria, we can use the OR operator, as in the example below:
In case we want to search for objects and it is enough to satisfy any of the criteria, we can use the OR operator, as in the example below:


<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CommitCRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account)(CommitCRM.LinkEnum.linkOR)
  <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CRM.Account)(CRM.LinkEnum.linkOR)
   
   
  accountSearch.AddCriteria(CommitCRM.Account.Fields.City, CommitCRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
  accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
  accountSearch.AddCriteria(CommitCRM.Account.Fields.City, CommitCRM.OperatorEnum.opEqual, <span style="color: #963A46;">"Chicago"</span>)
  accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, <span style="color: #963A46;">"Chicago"</span>)
  <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account) = accountSearch.FetchObjects()
  <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CRM.Account) = accountSearch.FetchObjects()
  <span style="color: #66AD3A;">'accounts now contains all CommitCRM.Account objects that satisfy any of the above criteria.</span>
  <span style="color: #66AD3A;">'accounts now contains all CRM.Account objects that satisfy any of the above criteria.</span>
</font>
</font>


If our search returns lots of objects, it may take some time to get the results back. If not all of the object's fields are need for the given task, we can pass a comma separated string with the field names to the '''CommitCRM.ObjectQuery.FetchObjects''' and the objects in the results will have only those fields populated.
If our search returns lots of objects, it may take some time to get the results back. If not all of the object's fields are need for the given task, we can pass a comma separated string with the field names to the '''CRM.ObjectQuery.FetchObjects''' and the objects in the results will have only those fields populated.


<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CommitCRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account)(CommitCRM.LinkEnum.linkOR)
  <span style="color: #3A3AFF;">Dim</span> accountSearch <span style="color: #3A3AFF;">As New</span> CRM.ObjectQuery(<span style="color: #3A3AFF;">Of</span> CRM.Account)(CRM.LinkEnum.linkOR)
   
   
  accountSearch.AddCriteria(CommitCRM.Account.Fields.City, CommitCRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
  accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, <span style="color: #963A46;">"New York"</span>)
  accountSearch.AddCriteria(CommitCRM.Account.Fields.City, CommitCRM.OperatorEnum.opEqual, <span style="color: #963A46;">"Chicago"</span>)
  accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, <span style="color: #963A46;">"Chicago"</span>)
  <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CommitCRM.Account) = accountSearch.FetchObjects(CommitCRM.Account.Fields.AccountREC_ID.Key & "," & CommitCRM.Account.Fields.City.Key)
  <span style="color: #3A3AFF;">Dim</span> accounts <span style="color: #3A3AFF;">As</span> List(<span style="color: #3A3AFF;">Of</span> CRM.Account) = accountSearch.FetchObjects(CRM.Account.Fields.AccountREC_ID.Key & "," & CRM.Account.Fields.City.Key)
  <span style="color: #66AD3A;">'CommitCRM.Account objects in the accounts list now contain only the AccountREC_ID and City fields.</span>
  <span style="color: #66AD3A;">'CRM.Account objects in the accounts list now contain only the AccountREC_ID and City fields.</span>
</font>
</font>


The table below explains the important methods of the '''CommitCRM.ObjectQuery''' class:
The table below explains the important methods of the '''CRM.ObjectQuery''' class:


{| class="wikitable"
{| class="wikitable"
Line 2,895: Line 2,895:
| (ByVal sField As String, ByVal opEnum As OperatorEnum, ByVal sValue As String)
| (ByVal sField As String, ByVal opEnum As OperatorEnum, ByVal sValue As String)
|  
|  
| Adds one criteria to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds one criteria to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is the internal field name (column '''API Field name''' in the Object derived classes tables),
First parameter is the internal field name (column '''API Field name''' in the Object derived classes tables),
second parameter is the criteria operator (see the table below)
second parameter is the criteria operator (see the table below)
Line 2,902: Line 2,902:
| Public Sub
| Public Sub
| '''AddCriteria'''
| '''AddCriteria'''
| (ByVal field As CmtField, ByVal opEnum As OperatorEnum, ByVal sValue As String)
| (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal sValue As String)
|
|
| Adds one criteria to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds one criteria to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is one of the '''CommitCRM.CmtField''' preinitialized objects included in Fields class in each of the '''CommitCRM.Object''' derived classes,
First parameter is one of the '''CRM.CrmField''' preinitialized objects included in Fields class in each of the '''CRM.Object''' derived classes,
second parameter is the criteria operator (see the table below)
second parameter is the criteria operator (see the table below)
and third parameter is the value ('''System.String''') to search for. This variation (or the one variations with the '''System.DateTime''' or '''System.Double''' as third parameter) of the '''AddCriteria''' method is the preferred way of adding criteria, unless there is no preinitialized '''CommitCRM.CmtField''' object for the field.
and third parameter is the value ('''System.String''') to search for. This variation (or the one variations with the '''System.DateTime''' or '''System.Double''' as third parameter) of the '''AddCriteria''' method is the preferred way of adding criteria, unless there is no preinitialized '''CRM.CrmField''' object for the field.
|-
|-
| Public Sub
| Public Sub
| '''AddCriteria'''
| '''AddCriteria'''
| (ByVal field As CmtField, ByVal opEnum As OperatorEnum, ByVal dtValue As DateTime)
| (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal dtValue As DateTime)
|  
|  
| Adds one criteria to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds one criteria to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is one of the '''CommitCRM.CmtField''' preinitialized objects included in Fields class in each of the '''CommitCRM.Object''' derived classes,
First parameter is one of the '''CRM.CrmField''' preinitialized objects included in Fields class in each of the '''CRM.Object''' derived classes,
second parameter is the criteria operator (see the table below)
second parameter is the criteria operator (see the table below)
and third parameter is the value ('''System.DateTime''') to search for. Use this variation to search in fields that are of '''DateTime''' type.
and third parameter is the value ('''System.DateTime''') to search for. Use this variation to search in fields that are of '''DateTime''' type.
Line 2,920: Line 2,920:
| Public Sub
| Public Sub
| '''AddCriteria'''
| '''AddCriteria'''
| (ByVal field As CmtField, ByVal opEnum As OperatorEnum, ByVal nValue As Integer)
| (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal nValue As Integer)
|  
|  
| Adds one criteria to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds one criteria to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is one of the '''CommitCRM.CmtField''' preinitialized objects included in Fields class in each of the '''CommitCRM.Object''' derived classes,
First parameter is one of the '''CRM.CrmField''' preinitialized objects included in Fields class in each of the '''CRM.Object''' derived classes,
second parameter is the criteria operator (see the table below)
second parameter is the criteria operator (see the table below)
and third parameter is the value ('''System.Integer''') to search for. Use this variation to search in fields that are of '''Integer''' type.
and third parameter is the value ('''System.Integer''') to search for. Use this variation to search in fields that are of '''Integer''' type.
Line 2,929: Line 2,929:
| Public Sub
| Public Sub
| '''AddCriteria'''
| '''AddCriteria'''
| (ByVal field As CmtField, ByVal opEnum As OperatorEnum, ByVal nValue As Double)
| (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal nValue As Double)
|
|
| Adds one criteria to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds one criteria to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is one of the '''CommitCRM.CmtField''' preinitialized objects included in Fields class in each of the '''CommitCRM.Object''' derived classes,
First parameter is one of the '''CRM.CrmField''' preinitialized objects included in Fields class in each of the '''CRM.Object''' derived classes,
second parameter is the criteria operator (see the table below)
second parameter is the criteria operator (see the table below)
and third parameter is the value ('''System.Double''') to search for. Use this variation to search in fields that are of '''Double''' type.
and third parameter is the value ('''System.Double''') to search for. Use this variation to search in fields that are of '''Double''' type.
Line 2,940: Line 2,940:
| (ByVal sField As String, ByVal sortEnum As SortDirectionEnum)
| (ByVal sField As String, ByVal sortEnum As SortDirectionEnum)
|
|
| Adds a sort expression to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds a sort expression to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is the internal field name (column '''API Field name''' in the Object derived classes tables),
First parameter is the internal field name (column '''API Field name''' in the Object derived classes tables),
second parameter is '''CommitCRM.SortDirectionEnum''' ('''sortASC''' or '''sortDESC''').
second parameter is '''CRM.SortDirectionEnum''' ('''sortASC''' or '''sortDESC''').
|-
|-
| Public Sub
| Public Sub
| '''AddSortExpression'''
| '''AddSortExpression'''
| (ByVal field As CmtField, ByVal sortEnum As SortDirectionEnum)
| (ByVal field As CrmField, ByVal sortEnum As SortDirectionEnum)
|  
|  
| Adds a sort expression to the initialized '''CommitCRM.ObjectQuery''' object instance.
| Adds a sort expression to the initialized '''CRM.ObjectQuery''' object instance.
First parameter is one of the '''CommitCRM.CmtField''' preinitialized objects included in Fields class in each of the '''CommitCRM.Object''' derived classes,
First parameter is one of the '''CRM.CrmField''' preinitialized objects included in Fields class in each of the '''CRM.Object''' derived classes,
second parameter is '''CommitCRM.SortDirectionEnum''' ('''sortASC''' or '''sortDESC''').
second parameter is '''CRM.SortDirectionEnum''' ('''sortASC''' or '''sortDESC''').
|-
|-
| Public Function
| Public Function
Line 2,956: Line 2,956:
| ()
| ()
| As List(Of T)
| As List(Of T)
| Executes the constructed query and returns a list of objects (of type '''T''' where T is any of the '''CommitCRM.Object''' derived classes) that satisfies the criteria.
| Executes the constructed query and returns a list of objects (of type '''T''' where T is any of the '''CRM.Object''' derived classes) that satisfies the criteria.
|}
|}


Below is the table with the available operators ('''CommitCRM.OperatorEnum''') used in the AddCriteria methods.
Below is the table with the available operators ('''CRM.OperatorEnum''') used in the AddCriteria methods.


{| class="wikitable"
{| class="wikitable"
Line 2,966: Line 2,966:
! Description
! Description
|-
|-
| '''CommitCRM.OperatorEnum.opEqual'''
| '''CRM.OperatorEnum.opEqual'''
| Searches for objects using the exact match (equals) operator
| Searches for objects using the exact match (equals) operator
|-
|-
| '''CommitCRM.OperatorEnum.opGreaterThan'''
| '''CRM.OperatorEnum.opGreaterThan'''
| Searches for objects whose value is greater than the value passed in the third parameter in AddCriteria method.
| Searches for objects whose value is greater than the value passed in the third parameter in AddCriteria method.
|-
|-
| '''CommitCRM.OperatorEnum.opGreaterThanOrEqual'''
| '''CRM.OperatorEnum.opGreaterThanOrEqual'''
| Searches for objects whose value is greater or equal than the value passed in the third parameter in AddCriteria method.
| Searches for objects whose value is greater or equal than the value passed in the third parameter in AddCriteria method.
|-
|-
| '''CommitCRM.OperatorEnum.opLessThan'''
| '''CRM.OperatorEnum.opLessThan'''
| Searches for objects whose value is less than the value passed in the third parameter in AddCriteria method.
| Searches for objects whose value is less than the value passed in the third parameter in AddCriteria method.
|-
|-
| '''CommitCRM.OperatorEnum.opLessThanOrEqual'''
| '''CRM.OperatorEnum.opLessThanOrEqual'''
| Searches for objects whose value is less than or equal the value passed in the third parameter in AddCriteria method.
| Searches for objects whose value is less than or equal the value passed in the third parameter in AddCriteria method.
|-
|-
| '''CommitCRM.OperatorEnum.opLike'''
| '''CRM.OperatorEnum.opLike'''
| Combined with % (percent sign) in the value passed in the third parameter in AddCriteria method can be used for search with broader match.
| Combined with % (percent sign) in the value passed in the third parameter in AddCriteria method can be used for search with broader match.
|-
|-
| '''CommitCRM.OperatorEnum.opNot'''
| '''CRM.OperatorEnum.opNot'''
| Searches for objects whose value differs from the one passed in the third parameter in AddCriteria method.
| Searches for objects whose value differs from the one passed in the third parameter in AddCriteria method.
|-
|-
| '''CommitCRM.OperatorEnum.opNotLike'''
| '''CRM.OperatorEnum.opNotLike'''
|
|
|}
|}
Line 2,993: Line 2,993:
= Field length limitations =
= Field length limitations =


Most of the database fields (analogous the properties mapped to these fields) have limits on data length that can be accepted. If more than the allowed length is assigned to a field, data is truncated to the length the field is capable of holding and the rest is discarded. Depending on the '''CommitCRM.Config.RaiseExceptionIfDatabaseFieldTruncated''' setting ('''True/False'''), the operation could raise an exception alerting you that not all of the data was accepted. By default this setting is off ('''False''') resulting in silent truncation of the extra data. Set the '''CommitCRM.Config.RaiseExceptionIfDatabaseFieldTruncated''' to '''True''' if this behavior is not acceptable.
Most of the database fields (analogous the properties mapped to these fields) have limits on data length that can be accepted. If more than the allowed length is assigned to a field, data is truncated to the length the field is capable of holding and the rest is discarded. Depending on the '''CRM.Config.RaiseExceptionIfDatabaseFieldTruncated''' setting ('''True/False'''), the operation could raise an exception alerting you that not all of the data was accepted. By default this setting is off ('''False''') resulting in silent truncation of the extra data. Set the '''CRM.Config.RaiseExceptionIfDatabaseFieldTruncated''' to '''True''' if this behavior is not acceptable.


Below is an example of how to switch this setting ON:
Below is an example of how to switch this setting ON:


<font face="courier new" size="3">
<font face="courier new" size="3">
  <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CommitCRM.Config
  <span style="color: #3A3AFF;">Dim</span> config <span style="color: #3A3AFF;">As New</span> CRM.Config
  config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
  config.AppName = <span style="color: #963A46;">"VB.NET Demo"</span>
  config.CommitDllFolder = <span style="color: #963A46;">"C:\CommitCRM\ThirdParty\UserDev"</span>
  config.DllFolder = <span style="color: #963A46;">"C:\RangerMSP\ThirdParty\UserDev"</span>
  config.CommitDbFolder = <span style="color: #963A46;">"C:\CommitCRM\db"</span>
  config.DbFolder = <span style="color: #963A46;">"C:\RangerMSP\db"</span>
  config.RaiseExceptionIfDatabaseFieldTruncated = <span style="color: #3A3AFF;">True</span><span style="color: #66AD3A;">'the setting is ON now</span>
  config.RaiseExceptionIfDatabaseFieldTruncated = <span style="color: #3A3AFF;">True</span><span style="color: #66AD3A;">'the setting is ON now</span>
   
   
  <span style="color: #66AD3A;">'Initialize the CommitCRM.Application</span>
  <span style="color: #66AD3A;">'Initialize the CRM.Application</span>
  CommitCRM.Application.Initialize(config)
  CRM.Application.Initialize(config)
   
   
  <span style="color: #3A3AFF;">Dim</span> account <span style="color: #3A3AFF;">As New</span> CommitCRM.Account
  <span style="color: #3A3AFF;">Dim</span> account <span style="color: #3A3AFF;">As New</span> CRM.Account
  account.FileAs = <span style="color: #963A46;">"ACME Company"</span>
  account.FileAs = <span style="color: #963A46;">"ACME Company"</span>
  account.Dear = <span style="color: #963A46;">"Mr."</span>
  account.Dear = <span style="color: #963A46;">"Mr."</span>
Line 3,017: Line 3,017:


= See Also =
= See Also =
*[[Commit API Developers Guide|CommitCRM API Developers Guide]]
*[[API Developers Guide|RangerMSP API Developers Guide]]
*[[API Reference Manual]]
*[[API Reference Manual]]
[[Category:User Manuals]]
[[Category:User Manuals]]
[[Category:Integration]]
[[Category:Integration]]

Latest revision as of 10:25, 9 July 2020

User Manuals > API Developers Guide > VB.NET API

Disclaimer

This documentation refers to RangerMSP 5.6 or later version and assumes RangerMSP is installed and accessible on the local computer.

Introduction

This document demonstrates how to use the RangerMSP VB.NET API library in order to programmatically connect to your RangerMSP server and query or manipulate the RangerMSP database.


System Requirements

  • RangerMSP 5.6 or later.
  • Visual Basic .NET 2008 or Visual Basic .NET 2010.
  • CRMLib.dll (the RangerMSP VB.NET compiled library).

Getting Started

Libraries Setup

To download, compile and setup the libraries, please refer to VB.NET API Library Setup.

Start Basic Program

After you create your VB.NET project, you'll need to add a reference to the CRMLib.dll file, in order to have access to the RangerMSP library classes.

Each application using the library will have to initialize on startup the CRM.Application object and terminate it on exit. Initialization method requires that you pass an object instance of CRM.Config class.

Connecting to the RangerMSP database can be done in two ways:

  1. Using a Local Server - run your program on the same server where the RangerMSP Server runs.
  2. Using Web API - run your program anywhere and connect to a remote RangerMSP server over Web services interface.

Connection parameters vary between these options. See the variations below:

Local Server

For connections to a local RangerMSP server configure the following settings:

  • AppName
This is free text, preferably the name of your application.
  • DllFolder
Behind the scenes the library uses the two RangerMSP API dlls: CmtDbEng.dll and CmtDbQry.dll.
In the default RangerMSP installation you'll find these files in 'C:\RangerMSP\ThirdParty\UserDev'.
Important Note: Always point to this folder and do not copy the dll files elsewhere. This is because when the RangerMSP version upgrade runs it also upgrades the dll files stored in this folder. This verifies that you will always be using the latest release.
  • DbFolder
Path to the RangerMSP database, default is 'C:\RangerMSP\db'.

Assuming these default values, we can configure the CRM.Config object like this:

Dim config As New CRM.Config
config.AppName = "VB.NET Demo"
config.DllFolder = "C:\RangerMSP\ThirdParty\UserDev"
config.DbFolder = "C:\RangerMSP\db"

You should of course ensure these paths are correct on your disk and modify the values accordingly.

Remote Server (Web API)

To connect to a remote RangerMSP server with the Web API, configure the following settings:

  • AppName
This is free text, preferably the name of your application.
  • WebAPIUrl
Url to the RangerMSP server running the Web API, either local or remote.
Url must include the http:// or https:// prefix, otherwise the API will not be able to connect.
Valid examples include http://localhost:4964/ and https://webapi.mycrmserver.com/.
  • Password
Your authorization password/token
  • UseWebAPI
Boolean value, must be set to True to use the Web API

Assuming these default values, we can configure the CRM.Config object like this:

Dim config As New CRM.Config
config.AppName = "VB.NET Demo"
config.WebAPIUrl = "http://localhost:4964/"
config.Password = "yourpassword"
config.UseWebAPI = True

Initialization

The configuration settings explained above are the only differences between connecting to a local RangerMSP server or remote RangerMSP server running the Web API.

Now we can initialize the CRM.Application object with these settings:

'CRM.Application.Initialize must be the first call before invoking any other RangerMSP library method
'and it should be done only once in the program's lifetime.
CRM.Application.Initialize(config)

If anything goes wrong, the above line will throw an exception of the CRM.Exception class. To prevent unexpected termination of the program execution, we recommend having any call to the RangerMSP library enclosed in a Try/Catch block.

Before exit, we terminate the CRM.Application object:

'Before exit we should call CRM.Application.Terminate to gracefully release all application resources
'and this should be done only once in the program's lifetime.
CRM.Application.Terminate()

The most basic VB.NET application that just connects to RangerMSP and terminates could look something like this:

Try
    Dim config As New CRM.Config
    config.AppName = "VB.NET Demo"
    config.DllFolder = "C:\RangerMSP\ThirdParty\UserDev"
    config.DbFolder = "C:\RangerMSP\db"

    CRM.Application.Initialize(config)

    'At this point we have successfully initialized the CRM.Application
    'and can start using the other library classes
Catch ex As Exception 
    Console.Out.Write(ex.Message)
Finally
    CRM.Application.Terminate()
End Try

Now that we have confirmed the connectivity to the RangerMSP server (if the above code successfully runs), we can continue adding more functionality to the example.

The library exposes as VB.NET classes the same RangerMSP objects (Account, Ticket etc.) available through the native RangerMSP API and you can refer to the API Reference Manual for database fields reference.


With any of these objects you can:

  • Search and query for objects with CRM.ObjectQuery that satisfy certain criteria.
  • Read and display the properties of the retrieved objects.
  • Update and save the properties of the retrieved objects.
  • Create and save new objects.


Now let's see how we can search for CRM.Account objects. We instantiate an object of the CRM.ObjectQuery class and pass CRM.Account class as generics parameter.

Dim accountSearch As New CRM.ObjectQuery(Of CRM.Account)

CRM.ObjectQuery class can accept any of the RangerMSP objects in this parameter, but we want to search for accounts now.


Next, we need to set criteria (or more than one) we want to search for:

accountSearch.AddCriteria(CRM.Ticket.Fields.City, CRM.OperatorEnum.opEqual, "New York")

The first parameter to the AddCriteria method is either a Shared object instance of CRM.CrmField class representing the field we want to look in or the internal API field name. Refer to the API Field Name column in the Account Class table for a complete list of the available fields for the CRM.Account class.

The second parameter is a compare operator. We here use the CRM.OperatorEnum.opEqual to get only exact matches. In order to get a broader match in the results you can use CRM.OperatorEnum.opLike operator.

The third parameter is the value we want to find. Prepending and/or appending % (percent) sign at the beginning and/or at the end while using CRM.OperatorEnum.opLike operator, will match the phrase even if in the middle of a sentence.

Now we can execute the search and retrieve the CRM.Account objects (if any):

Dim accounts As List(Of CRM.Account) = accountSearch.FetchObjects()

The above line will populate the List (System.Collections.Generic.List) with all CRM.Account objects that were found. Now we can use For Each - Next statement to iterate through the accounts:

For Each account In accounts
    Console.Out.WriteLine(account.CompanyName)
Next

Or we can manipulate these accounts:

For Each account In accounts
    If account.Zip.Length = 0 Then
        account.Zip = "10001"
        account.Save()
    End If
Next

We invoke the CRM.Account's Save method on both new or existing accounts. For a new account, invoking the Save method would insert a new account in the RangerMSP database. For an existing account, invoking the Save method would update the fields we modified in the existing account. This rule applies to all RangerMSP objects.

Another option is to add a new ticket for each of the accounts:

For Each account In accounts
    Dim ticket As New CRM.Ticket
    ticket.AccountREC_ID = account.AccountREC_ID
    ticket.Description = "Sample ticket for a NewYork account"
    ticket.Save()
Next

GetFieldValue and SetFieldValue methods

Each of the RangerMSP library objects have a set of properties that are exposed as VB.NET properties that you can directly manipulate or read from. You already saw few examples of these properties in the above examples, as: account.Zip or ticket.Description. This is the preferred and more intuitive way of accessing the RangerMSP fields.


However, there is also another way of achieving the same results, by invoking GetFieldValue and SetFieldValue and specifying the internal field name. These methods should only be used if necessary, for example, when updating user-defined custom fields which are not part of the class predefined basic fields.

Here is an equivalent of the above example that uses these two generic methods, instead of the object's properties:

For Each account In accounts
    Dim ticket As New CRM.Ticket
    ticket.SetFieldValue("FLDTKTCARDID", account.GetFieldValue("FLDCRDRECID"))
    ticket.SetFieldValue("FLDTKTPROBLEM", "Sample ticket for a NewYork account")
    ticket.Save()
Next

All internal field names are listed in Classes and Objects below.

Exception Handling

While working with the RangerMSP VB.NET library, some operations can fail. In this case the library will throw an exception of the CRM.Exception class. We recommend enclosing all calls to the RangerMSP library in a Try/Catch block.

To find out more about the exact error that ocured when an exception is thrown, you can inspect the CRM.Exception.Status property that holds the last RangerMSP Status value, or inspect the list of CRM.Exception.Codes (if any). Please refer to Error Codes Description for the description of these values.

Complete Program Sample

Module Module1

    Sub Main()

        Try
            'Setup the CRM.Config object
            Dim config As New CRM.Config
            config.AppName = "VB.NET Demo"
            config.DllFolder = "C:\RangerMSP\ThirdParty\UserDev"
            config.DbFolder = "C:\RangerMSP\db"

            'Initialize the CRM.Application
            CRM.Application.Initialize(config)

            'At this point we have successfully initialized the CRM.Application
            'and can start using the other library classes

            'search for "New York" in the FLDCRDCITY field
            Dim accountSearch As New CRM.ObjectQuery(Of CRM.Account)
            accountSearch.AddCriteria("FLDCRDCITY", CRM.OperatorEnum.opEqual, "New York")
            Dim accounts As List(Of CRM.Account) = accountSearch.FetchObjects()

            'loop through the retrieved accounts and output the CompanyName
            For Each account In accounts
                Console.Out.WriteLine(account.CompanyName)
            Next

       Catch ex As CRM.Exception 'here we catch RangerMSP specific error
            'we can inspect the RangerMSP status (exc.Status) 
            'exc.Codes contains all error codes last call generated

            'here we show the error message
            Console.Out.Write(ex.Message)

        Catch ex As Exception 
            Console.Out.Write(ex.Message)
        Finally
            CRM.Application.Terminate()
        End Try
    End Sub

End Module

Classes and Objects

The RangerMSP VB.NET API provides easy access to all objects using a class for each entity in the system (such as Account, Ticket, Asset, etc.).

All classes include:

  1. API functions and routines (which are derived from the base CRM.Object class).
  2. Class data fields, providing an easy way to update the object's data.


All RangerMSP's objects should be updated by setting the class data fields (properties) and then calling the Save method. For example, to create a new account programmatically (assuming CRM.Application was initialized successfully), one would use the following code snippet:

Dim account As New CRM.Account
account.FileAs = "ACME Company"
account.Dear = "Mr."
account.Contact = "John Doe"
account.Save()


Another option is using SetFieldData and GetFieldData as mentioned earlier, which provide low-level access to data fields. This option should only be used if necessary, for example, when updating user-defined fields which are not part of the class basic fields.


Object Class

The CRM.Object class is the base class for all RangerMSP accessible objects (as Ticket, Account, Asset, etc.). The public routines and functions exposed by the CRM.Object class are available to the derived classes.

Object Method Reference Table

Access modifier Method Arguments Return value Description
Public Sub SetFieldValue (sKey As String, sValue As String) Assigns the value (sValue) of the field passed in sKey argument. Save must be called for the change to take effect. Use this method to access user-defined custom fields.
Public Function GetFieldValue (sKey As String) As String Retrieves the value of the field passed in sKey argument. Use this method to access user-defined custom fields.
Public Sub Reload () Reloads the Object values from the database. The value of the object unique identifier (REC_ID, the exact name depends on the concrete derived object class)
Public Sub Reinit (sID As String) Same as Reload except the unique identifier is passed as argument.
Public Sub Save () Saves all modified properties of the object to the database.

Object derived classes

Classes explained in this section are derived from CRM.Object class and map directly to a native RangerMSP object (Account, Ticket, etc.).

Account Class

The CRM.Account class derives from CRM.Object and encapsulates the Account Fields. The following table lists all exposed CRM.Account properties.

Account Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property AccountREC_ID FLDCRDRECID As String 20
Public Property AccountManager FLDCRDASSIGNCARDID As String 20
Public Property CompanyName FLDCRDCOMPANY As String 60
Public Property Contact FLDCRDCONTACT As String 40
Public ReadOnly Property Status FLDCRDSUBCONTSTATUS As String 1
Public Property Assistant FLDCRDASSISTANT As String 20
Public Property ContractREC_ID FLDCRDBCRECID As String 20
Public Property AccountNumber FLDCRDCARDID2 As String 15
Public Property ID FLDCRDCARDID3 As String 15
Public Property PopupMessage FLDCRDCARDMESSAGE As String Unlimited
Public Property AddressLine1 FLDCRDADDRESS1 As String 40
Public Property AddressLine2 FLDCRDADDRESS2 As String 40
Public Property AddressLine3 FLDCRDADDRESS3 As String 40
Public Property City FLDCRDCITY As String 30
Public Property Country FLDCRDCOUNTRY As String 20
Public Property State FLDCRDSTATE As String 30
Public Property Zip FLDCRDZIP As String 15
Public Property CreationDate FLDCRDCREATEDATE As DateTime N/A
Public Property CreatedByUser FLDCRDCREATEUSERID As String 20
Public Property Dear FLDCRDDEAR As String 20
Public Property Department FLDCRDDEPARTMENT As String 35
Public Property DocumentsStoreDirectory FLDCRDDOCSFOLDER As String 100
Public Property EmailAddress1 FLDCRDEMAIL1 As String 70
Public Property EmailAddress2 FLDCRDEMAIL2 As String 70
Public Property AccountType FLDCRDENTITYKIND As Integer N/A
Public Property FaxNumber FLDCRDFAX1 As String 25
Public Property FaxNumberExt FLDCRDFAXDESC1 As String 15
Public Property FileAs FLDCRDFULLNAME As String 60
Public Property Type FLDCRDKIND As String 30
Public Property LastName FLDCRDLASTNAME As String 20
Public Property Notes FLDCRDNOTES As String Unlimited
Public Property Field FLDCRDPERSONID As String 20
Public Property Phone1Ext FLDCRDPHNDESC1 As String 40
Public Property Phone2Ext FLDCRDPHNDESC2 As String 40
Public Property Phone3Ext FLDCRDPHNDESC3 As String 15
Public Property Phone4Ext FLDCRDPHNDESC4 As String 15
Public Property Phone1 FLDCRDPHONE1 As String 25
Public Property Phone2 FLDCRDPHONE2 As String 25
Public Property Phone3 FLDCRDPHONE3 As String 25
Public Property Phone4 FLDCRDPHONE4 As String 25
Public Property Region FLDCRDREGIONCODE As String 15
Public Property PopupMessageDisplayIndication FLDCRDSHOWMESSAGE As String 1
Public Property SubContractCode FLDCRDSUBCODE As String 15
Public Property Salutation FLDCRDSUFFIX As String 20
Public Property Tax1 FLDCRDTAXCODE1 As String 3
Public Property Tax2 FLDCRDTAXCODE2 As String 3
Public Property Title FLDCRDTITLE As String 30
Public Property LastUpdatedBy FLDCRDUPDATEUSERID As String 20
Public Property WebAddress1 FLDCRDURL1 As String 100
Public Property WebAddress2 FLDCRDURL2 As String 100
Public Property Status FLDCRDUSER1 As String 30
Public Property Field1 FLDCRDUSER2 As String 30
Public Property Field2 FLDCRDUSER3 As String 30
Public Property Field3 FLDCRDUSER4 As String 30
Public Property Field4 FLDCRDUSER5 As String 30

Ticket Class

The CRM.Ticket class derives from CRM.Object and encapsulates the Ticket Fields. The following table lists all exposed CRM.Ticket properties.

Ticket Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property TicketREC_ID FLDTKTRECID As String 20
Public Property AccountREC_ID FLDTKTCARDID As String 20
Public Property AssetREC_ID FLDTKTASSETRECID As String 20
Public Property ContactREC_ID FLDTKTCONTACTID As String 20
Public Property ContractREC_ID FLDTKTBCRECID As String 20
Public Property EmployeeREC_ID FLDTKTWORKERID As String 20
Public Property TicketPriority FLDTKTPRIORITY As Integer N/A
Public Property TicketNumber FLDTKTTICKETNO As String 20
Public Property Description FLDTKTPROBLEM As String Unlimited
Public Property TicketType FLDTKTKIND As String 25
Public Property Source FLDTKTSOURCE As String 30
Public Property EstimatedDurationTime FLDTKTSCHEDLENESTIM As Integer N/A
Public Property ShowTicketInDispatcher FLDTKTFORDISPATCH As String 1
Public Property Status FLDTKTSTATUS As Integer N/A
Public Property CreatedByUser FLDTKTCREATEUSER As String 20
Public Property DueDate FLDTKTDUEDATETIME As DateTime N/A
Public Property Resolution FLDTKTSOLUTION As String Unlimited
Public ReadOnly Property UpdateDate FLDTKTUPDATEDATE As DateTime N/A

Asset Class

The CRM.Asset class derives from CRM.Object and encapsulates the Asset Fields. The following table lists all exposed CRM.Asset properties.

Asset Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property AssetREC_ID FLDASTRECID As String 20
Public Property AssetCode FLDASTASSETCODE As String 30
Public Property AssetType FLDASTASSETTYPE As String 1
Public Property AssetName FLDASTNAME As String 60
Public Property Status FLDASTSTATUS As String 1
Public Property SerialNo FLDASTSERIALNO As String 30
Public Property AccountREC_ID FLDASTACCRECID As String 20
Public Property ContactREC_ID FLDASTCONTACTRECID As String 20
Public Property CreatedByUser FLDASTCREATEUSER As String 20
Public Property PurchaseDate FLDASTCUSTPURDATE As DateTime N/A
Public Property PurchasedFromUs FLDASTCUSTPURFROMUS As String 1
Public Property PurchaseInvoice FLDASTCUSTPUROURINV As String 15
Public Property CustomerPO FLDASTCUSTPURPO As String 15
Public Property PurchasePrice FLDASTCUSTPURPRICE As Double N/A
Public Property DeliveredDate FLDASTDELIVEDATE As DateTime N/A
Public Property Description FLDASTDESC As String Unlimited
Public Property InstalledBy FLDASTINSTALBY As String 20
Public Property InstalledDate FLDASTINSTALDATE As DateTime N/A
Public Property LicenseCodes FLDASTLICENSECODE As String Unlimited
Public Property LicenseKeys FLDASTLICENSEKEYS As String Unlimited
Public Property LicenseNotes FLDASTLICENSENOTES As String Unlimited
Public Property Location FLDASTLOCATION As String 50
Public Property Manufacturer FLDASTMANUFACTURER As String 40
Public Property MnfSerialNo FLDASTMNFSERIALNO As String 30
Public Property Model FLDASTMODEL As String 20
Public Property Notes FLDASTNOTES As String Unlimited
Public Property Quantity FLDASTQUANTITY As Double N/A
Public Property LastUpdateBy FLDASTUPDATEUSER As String 20
Public Property Field1 FLDASTUSER1 As String 25
Public Property Field2 FLDASTUSER2 As String 25
Public Property Field3 FLDASTUSER3 As String 25
Public Property Field4 FLDASTUSER4 As String 25
Public Property Field5 FLDASTUSER5 As String 25
Public Property Date1 FLDASTUSERDATE1 As DateTime N/A
Public Property Number1 FLDASTUSERNUMBER1 As Double N/A
Public Property VendorPurchasedDate FLDASTVENDORDATEPURC As DateTime N/A
Public Property VendorInvoice FLDASTVENDORINVNO As String 15
Public Property VendorPO FLDASTVENDOROURPO As String 15
Public Property VendorPrice FLDASTVENDORPRICE As Double N/A
Public Property Vendor FLDASTVENDORRECID As String 20
Public Property VendorSerialNo FLDASTVENDORSERNO As String 30
Public Property VendorWarrantyExpDate FLDASTVENDORWARREXP As DateTime N/A
Public Property Version FLDASTVERSION As String 15
Public Property WarrantyLicenseExp FLDASTWARREXPDATE As DateTime N/A

Calendar Class

The CRM.Calendar class derives from CRM.Object and encapsulates the Calendar Fields of event type Appointment. The following table lists all exposed CRM.Calendar properties.

Calendar Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property CalendarREC_ID FLDEVTRECID As String 20
Public Property EventType FLDEVTWRITETOID As Integer N/A
Public Property EmployeeREC_ID FLDEVTWORKERID As String 20
Public Property PrivateUser FLDEVTPRIVATEID As String 20
Public Property AccountREC_ID FLDEVTCARDID As String 20
Public Property ContactREC_ID FLDEVTCONTACTID As String 20
Public Property DocumentREC_ID FLDEVTDOCID As String 20
Public Property DoneIndication FLDEVTDONE As Boolean N/A
Public Property [Date] FLDEVTEVENTDATE As DateTime N/A
Public Property Description FLDEVTFREETEXT As String Unlimited
Public Property TimeStart FLDEVTFROMTIME As String N/A
Public Property TimeEnd FLDEVTTOTIME As String N/A
Public Property RelLinkREC_ID FLDEVTLINKRECID As String 20
Public Property Field1 FLDEVTFAMILY As String 50
Public Property Field2 FLDEVTACTION As String 50
Public Property Field3 FLDEVTPLACE As String 40
Public Property Field4 FLDEVTPLACE1 As String 30
Public Property Field5 FLDEVTPLACE2 As String 30
Public Property CreatedByUser FLDEVTCREATEUSERID As String 20
Public Property LastUpdateByUser FLDEVTUPDATEUSER As String 20

Task Class

The CRM.Task class derives from CRM.Object and encapsulates the Calendar Fields of event type Task. The following table lists all exposed CRM.Task properties.

Task Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property TaskREC_ID FLDEVTRECID As String 20
Public Property EventType FLDEVTWRITETOID As Integer N/A
Public Property EmployeeREC_ID FLDEVTWORKERID As String 20
Public Property PrivateUser FLDEVTPRIVATEID As String 20
Public Property AccountREC_ID FLDEVTCARDID As String 20
Public Property ContactREC_ID FLDEVTCONTACTID As String 20
Public Property DocumentREC_ID FLDEVTDOCID As String 20
Public Property DoneIndication FLDEVTDONE As Boolean N/A
Public Property [Date] FLDEVTEVENTDATE As DateTime N/A
Public Property Description FLDEVTFREETEXT As String Unlimited
Public Property TimeStart FLDEVTFROMTIME As String N/A
Public Property RelLinkREC_ID FLDEVTLINKRECID As String 20
Public Property Field1 FLDEVTFAMILY As String 50
Public Property Field2 FLDEVTACTION As String 50
Public Property Field3 FLDEVTPLACE As String 40
Public Property Field4 FLDEVTPLACE1 As String 30
Public Property Field5 FLDEVTPLACE2 As String 30
Public Property CreatedByUser FLDEVTCREATEUSERID As String 20
Public Property LastUpdateByUser FLDEVTUPDATEUSER As String 20

Charge Class

The CRM.Charge class derives from CRM.Object and encapsulates the Charge Fields. The following table lists all exposed CRM.Charge properties.

Charge Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property ChargeREC_ID FLDSLPRECID As String 20
Public Property AccountREC_ID FLDSLPCARDID As String 20
Public Property EmployeeREC_ID FLDSLPWORKERID As String 20
Public Property ChargedItem FLDSLPITEMID As String 20
Public Property ContractREC_ID FLDSLPBCRECID As String 20
Public Property TicketREC_ID FLDSLPTICKETID As String 20
Public Property [Date] FLDSLPSLIPDATE As DateTime N/A
Public Property Description FLDSLPDESC As String Unlimited
Public Property Units_Hours FLDSLPQUANTITY As Double N/A
Public Property HourlyBased FLDSLPITEMUNITISHOUR As Boolean N/A
Public Property AdjustAmount FLDSLPADJUSTAMOUNT As Double N/A
Public Property AdjustPercent FLDSLPADJUSTPERCENT As Double N/A
Public AdjustType FLDSLPADJUSTTYPE As String 1
Public Property FromTime FLDSLPSTARTTIME As String N/A
Public Property ToTime FLDSLPENDTIME As String N/A
Public Property Price_Rate FLDSLPPRICE As Double N/A
Public Property Billable FLDSLPBILLKIND As String 1
Public Property Billed FLDSLPSTAGE As String 1
Public Property Field1 FLDSLPUSER1 As String 25
Public Property CreateUser FLDSLPCREATEUSER As String 20

Quote Class

The CRM.Quote class derives from CRM.Object. The following table lists all exposed CRM.Quote properties.

Quote Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property QuoteREC_ID FLDQTERECID As String 20
Public Property AccountREC_ID FLDQTEACCOUNTRECID As String 20
Public Property Status FLDQTESTATUS As String 1
Public Property BillToAddress FLDQTEBILLTOADDRESS As String Unlimited
Public Property BillToContactREC_ID FLDQTECONTACTRECID As String 20
Public Property QuoteDate FLDQTEQUOTEDATE As DateTime N/A
Public Property ShipToContactREC_ID FLDQTESHIPTOCONTACT As String 20
Public Property ShipToAddress FLDQTESHIPTOADDRESS As String Unlimited
Public Property ContractREC_ID FLDQTEBCRECID As String 20
Public Property HeaderNotes FLDQTEHEADERNOTES As String Unlimited
Public Property FooterNotes FLDQTEFOOTERNOTES As String Unlimited
Public ReadOnly Property TotalAfterTax FLDQTETOTALAFTERTAX As Double N/A
Public ReadOnly Property TotalTax1 FLDQTETOTALTAX1 As Double N/A
Public ReadOnly Property TotalTax2 FLDQTETOTALTAX2 As Double N/A
Public ReadOnly Property Tax1 FLDQTETAX1 As Double N/A
Public ReadOnly Property Tax2 FLDQTETAX2 As Double N/A
Public ReadOnly Property TotalAfterDiscount FLDQTETOTALAFTERDISC As Double N/A
Public ReadOnly Property Discount FLDQTEDISCOUNT As Double N/A
Public ReadOnly Property TotalForCustomer FLDQTETOTAL4CUSTOMER As Double N/A
Public Property IsPublic FLDQTEISPUBLIC As Boolean N/A
Public Property Audit FLDQTEAUDIT As String Unlimited
Public ReadOnly Property QuoteNumber FLDQTEQUOTENO As Integer N/A
Public Property QuoteName FLDQTEQUOTENAME As String 100
Public Property QuoteReference FLDQTEREFERENCE As String 20
Public Property ManagerRec_ID FLDQTEWORKERID As String 20
Public Property QuoteUserField1 FLDQTEUSER1 As String 30
Public Property QuoteUserField2 FLDQTEUSER2 As String 30
Public Property QuoteUserField3 FLDQTEUSER3 As String 30
Public Property QuoteNotes FLDQTENOTES As String Unlimited
Public ReadOnly Property WonConvertedTo FLDQTEWONCONVERTEDTO As String 1
Public ReadOnly Property SignatureEmail FLDQTECAFREEEMAIL As String 100
Public ReadOnly Property SignatureName FLDQTECAFREENAME As String 50
Public ReadOnly Property SignatureText FLDQTECAFREESIGNATRE As String 30
Public ReadOnly Property SignatureIPAddress FLDQTECAIPADDRESS As String 15
Public ReadOnly Property SignatureDateAndTime FLDQTECATIMESTAMP As DateTime N/A
Public ReadOnly Property SignatureWebUserName FLDQTECAWEBUSERNAME As String 70
Public ReadOnly Property SignatureWebUserREC_ID FLDQTECAWEBUSERRECID As String 20
Public ReadOnly Property CreatedByUser FLDQTECREATEUSER As String 20
Public ReadOnly Property LastUpdateByUser FLDQTEUPDATEUSER As String 20
Public ReadOnly Property CreatedDate FLDQTECREATEDATE As DateTime N/A
Public ReadOnly Property UpdateDate FLDQTEUPDATEDATE As DateTime N/A


QuoteLine Class

The CRM.QuoteLine class derives from CRM.Object. The following table lists all exposed CRM.QuoteLine properties.

QuoteLine Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property QuoteLineREC_ID FLDQTLRECID As String 20
Public Property QuoteREC_ID FLDQTLQUOTERECID As String 20
Public Property ItemREC_ID FLDQTLITEMRECID As String 20
Public ReadOnly Property ItemGroup FLDQTLITEMTYPEGROUP As String 1
Public Property Quantity FLDQTLQUANTITY As Double N/A
Public Property Price FLDQTLPRICE As Double N/A
Public Property DiscountMarkup FLDQTLADJUST As String 1
Public ReadOnly Property DiscountTotalAmountForCustomer FLDQTLADJAMTDIS4CUST As Double N/A
Public ReadOnly Property DiscountPercentageForCustomer FLDQTLADJPERDIS4CUST As Double N/A
Public ReadOnly Property LineTotal FLDQTLBILLTOTAL As Double N/A
Public ReadOnly Property LineTotalForCustomer FLDQTLTOTAL4CUSTOMER As Double N/A
Public ReadOnly Property LineType FLDQTLLINETYPE As String 1
Public Property LineSortOrder FLDQTLORDER As Integer N/A
Public ReadOnly Property PriceForCustomerAfterMarkup FLDQTLPRICE4CUSTOMER As Double N/A
Public Property AdjustAmount FLDQTLADJUSTAMOUNT As Double N/A
Public Property AdjustPercent FLDQTLADJUSTPERCENT As Double N/A
Public Property AdjustType FLDQTLADJUSTTYPE As String 1
Public Property Description FLDQTLDESCRIPTION As String Unlimited
Public ReadOnly Property CreatedByUser FLDQTLCREATEUSER As String 20
Public ReadOnly Property LastUpdateByUser FLDQTLUPDATEUSER As String 20
Public ReadOnly Property CreatedDate FLDQTLCREATEDATE As DateTime N/A
Public ReadOnly Property UpdateDate FLDQTLUPDATEDATE As DateTime N/A

QuoteLine Helper Methods

Besides the get/set properties, QuoteLine supports number of helper methods.

QuoteLine Helper Methods Table

Access modifier Return value Property Arguments Description
Public Sub SetQuoteLineItem (ByVal sItemREC_ID As String, ByVal dblQuantity As Double, ByVal dblPrice As Double) Fills the appropriate fields for inserting Item type QuoteLine.
Public Sub SetQuoteLineItemWithDiscount (ByVal sItemREC_ID As String, ByVal dblQuantity As Double, ByVal dblPrice As Double, ByVal dblDiscount As Double, ByVal bByPercent As Boolean) Fills the appropriate fields for inserting Item type QuoteLine specifying a discount.
Public Sub SetQuoteLineItemWithMarkup (ByVal sItemREC_ID As String, ByVal dblQuantity As Double, ByVal dblPrice As Double, ByVal dblMarkup As Double, ByVal bByPercent As Boolean) Fills the appropriate fields for inserting Item type QuoteLine specifying a markup.
Public Sub SetQuoteLineText (ByVal sText As String) Sets the appropriate field for inserting Text type QuoteLine.
Public Sub MoveLineAboveLine (ByVal lnAbove As QuoteLine) Moves the QuoteLine position above the lnAbove position. The QuoteLine in lnAbove must point to an existing QuoteLine. This method essentially assigns the LineSortOrder property to the same value lnAbove holds and lnAbove is pushed down. You must call Save for the change to become effective.
Public Sub MoveToBottom () Moves the QuoteLine position at the bottom of the Quote. This method essentially assigns the LineSortOrder property to -999 which is the value for the last position in the Quote. You must call Save for the change to become effective.
Public Sub Delete () Deletes the QuoteLine.

Document Class

The CRM.Document class derives from CRM.Object and encapsulates the Document Fields. The following table lists all exposed CRM.Document properties.

Document Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property DocumentREC_ID FLDDOCRECID As String 20
Public Property DocumentDate FLDDOCDOCDATE As DateTime N/A
Public Property Subject FLDDOCDOCUMENTDESC As String 100
Public Property RelLinkREC_ID FLDDOCLINKRECID As String 20
Public Property AccountREC_ID FLDDOCCARDID As String 20
Public Property ContactREC_ID FLDDOCCONTACTID As String 20
Public Property Field1 FLDDOCTRANSPORT As String 20
Public Property Field2 FLDDOCFOLDER As String 20
Public Property Field3 FLDDOCUMENTPLACE As String 20
Public Property FilePathAndName FLDDOCDOCUMENTNAME As String 240
Public Property Category FLDDOCTREEID As Integer N/A
Public Property EmployeeREC_ID FLDDOCWORKERID As String 20
Public Property CreatedByUser FLDDOCCREATEUSER As String 20
Public Property LastUpdateByUser FLDDOCUPDATEUSER As String 20

HistoryNote Class

The CRM.HistoryNote class derives from CRM.Object and encapsulates the History Note Fields. The following table lists all exposed CRM.HistoryNote properties.

HistoryNote Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property HistoryNoteREC_ID FLDHISRECID As String 20
Public Property [Date] FLDHISNOTEDATETIME As DateTime N/A
Public Property Description FLDHISDESCRIPTION As String Unlimited
Public Property RelLinkREC_ID FLDHISLINKRECID As String 20
Public Property Field FLDHISUSER1 As String 25
Public Property About FLDHISKIND As String 15
Public Property EmployeeREC_ID FLDHISWORKERID As String 20
Public Property AccountREC_ID FLDHISCARDID As String 20
Public Property Contact FLDHISCONTACTID As String 20
Public Property DocumentREC_ID FLDHISDOCID As String 20
Public Property CreatedByUser FLDHISCREATEUSER As String 20

Item Class

The CRM.Item class derives from CRM.Object and encapsulates the Item Fields. The following table lists all exposed CRM.Item properties.

Item Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property ItemREC_ID FLDITMRECID As String 20
Public Property ItemGroup FLDITMITEMTYPEGROUP As String 1
Public Property ItemCode FLDITMITEMNO As String 30
Public Property ItemName FLDITMNAME As String 60
Public Property PriceSource FLDITMPRICESOURCE As String 1
Public Property PricePerHour_Unit FLDITMUNITISHOUR As String 1
Public Property Price FLDITMUNITPRICE As Double N/A
Public Property Cost FLDITMSTANDARDCOST As Double N/A
Public Property Tax1 FLDITMTAXCODE1 As String 3
Public Property Tax2 FLDITMTAXCODE2 As String 3
Public Property Tax3 FLDITMTAXCODE3 As String 3
Public Property DescriptionByName FLDITMDESCBYNAME As String 1
Public Property Description FLDITMDESC As String Unlimited
Public Property Suspend FLDITMSUSPENDED As String 1
Public Property Notes FLDITMNOTES As String Unlimited
Public Property Field1 FLDITMUSER1 As String 25
Public Property CreateUser FLDITMCREATEUSER As String 20

KnowledgeBaseArticle Class

The CRM.KnowledgeBaseArticle class derives from CRM.Object and encapsulates the Knowledge Base Article Fields. The following table lists all exposed CRM.KnowledgeBaseArticle properties.

KnowledgeBaseArticle Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property KnowledgeBaseArticleREC_ID FLDKBARECID As String 20
Public Property DocumentDate FLDKBACREATEDATE As DateTime N/A
Public Property Title FLDKBATITLE As String 250
Public Property Problem FLDKBAPROBLEM As String Unlimited
Public Property Solution FLDKBASOLUTION As String Unlimited
Public Property Status FLDKBASTATUS As String 1
Public Property Category FLDKBACATEGORY As String 100
Public Property [Public] FLDKBAISPUBLIC As String 1
Public Property CreatedByUser FLDKBACREATEUSER As String 20
Public Property LastUpdateByUser FLDKBAUPDATEUSER As String 20

Opportunity Class

The CRM.Opportunity class derives from CRM.Object and encapsulates the Opportunity Fields. The following table lists all exposed CRM.Opportunity properties.

Opportunity Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property OpportunityREC_ID FLDOPPRECID As String 20
Public Property OpportunityName FLDOPPNAME As String 50
Public Property OpportunityID FLDOPPUSERID As String 15
Public Property AccountREC_ID FLDOPPCARDID As String 20
Public Property Source FLDOPPSOURCE As String 30
Public Property CloseDate FLDOPPCLOSEDATE As DateTime N/A
Public Property Manager FLDOPPWORKERID As String 20
Public Property OpenDate FLDOPPOPENDATE As DateTime N/A
Public Property CloseByDate FLDOPPESTDATE As DateTime N/A
Public Property Amount FLDOPPAMOUNT As Double N/A
Public Property Probability FLDOPPPROBABILITY As Double N/A
Public Property Stage FLDOPPSTAGE As String 30
Public Property Status FLDOPPSTATUS As Integer N/A
Public Property ClosingAmount FLDOPPCLOSEAMOUNT As Double N/A
Public Property Description FLDOPPDESCRIPTION As String Unlimited
Public Property OpportunityType FLDOPPKIND As String 30
Public Property OpportunityReason FLDOPPREASON As String 30
Public Property Note FLDOPPNOTES As String Unlimited
Public Property Territory FLDOPPREGION As String 30
Public Property Field1 FLDOPPUSER1 As String 30
Public Property Field2 FLDOPPUSER2 As String 30
Public Property Field3 FLDOPPUSER3 As String 30
Public Property CreatedByUser FLDOPPCREATEUSER As String 20
Public Property LastUpdateByUser FLDOPPUPDATEUSER As String 20

Contact Class

The CRM.Contact class derives from CRM.Object and it represents the secondary contacts to a CRM.Account. The following table lists all exposed CRM.Contact properties.

Contact Properties Reference Table

Access modifier Property API Field Name Return value Field length
Public ReadOnly Property ContactREC_ID FLDCRDRECID As String 20
Public Property ParentAccountREC_ID FLDCRDASSIGNCARDID As String 20
Public Property AccountType FLDCRDENTITYKIND As Integer N/A
Public Property CompanyName FLDCRDCOMPANY As String 60
Public Property Contact FLDCRDCONTACT As String 40
Public Property Salutation FLDCRDSUFFIX As String 20
Public Property Title FLDCRDTITLE As String
Public Property Department FLDCRDDEPARTMENT As String 35
Public Property Dear FLDCRDDEAR As String 20
Public Property LastName FLDCRDLASTNAME As String 20
Public Property AddressLine1 FLDCRDADDRESS1 As String 40
Public Property AddressLine2 FLDCRDADDRESS2 As String 40
Public Property AddressLine3 FLDCRDADDRESS3 As String 40
Public Property City FLDCRDCITY As String 30
Public Property Country FLDCRDCOUNTRY As String 20
Public Property Zip FLDCRDZIP As String 15
Public Property State FLDCRDSTATE As String 30
Public Property EmailAddress1 FLDCRDEMAIL1 As String 70
Public Property Phone1 FLDCRDPHONE1 As String 25
Public Property Phone2 FLDCRDPHONE2 As String 25
Public Property FaxNumber FLDCRDFAX1 As String 25
Public Property Phone1Ext FLDCRDPHNDESC1 As String 40
Public Property Phone2Ext FLDCRDPHNDESC2 As String 40
Public Property FaxNumberExt FLDCRDFAXDESC1 As String 15
Public Property SubContractCode FLDCRDSUBCODE As String 15
Public Property Birthday FLDCRDBIRTHDAY As DateTime N/A
Public Property Notes FLDCRDNOTES As String Unlimited
Public Property CreationDate FLDCRDCREATEDATE As DateTime N/A
Public Property CreatedByUser FLDCRDCREATEUSERID As String 20
Public Property LastUpdatedBy FLDCRDUPDATEUSERID As String 20

Config Class

CRM.Config class is used to pass the global configuration settings to the CRM.Application Initialize method.

Property Type Required Description
AppName String Yes Maximum 15 chars, string that best identifies your application.
DllFolder String Yes Exact path to the folder where RangerMSP API DLLs are located (CmtDbEng.dll and CmtDbQry.dll, usually "C:\RangerMSP\ThirdParty\UserDev").
DbFolder String Yes Exact path to the folder where RangerMSP database is located (usually "C:\RangerMSP\db").
InitCRMApiDll Boolean No Initializes the CmtDbEng.dll file, which is required for proper functioning of all update functions. True by default (recommended setting). Set it to False only if you know what you are doing.
InitCRMQryDll Boolean No Initializes the CmtDbQry.dll file which is required for proper functioning of all search/query functions. True by default (recommended setting). Set it to False only if you know what you are doing.
Params List(Of KeyValuePair(Of String, String)) No Not used, reserved for future use
RaiseExceptionIfDatabaseFieldTruncated Boolean No Specifies whether truncation of a field value will raise an exception. All string properties/fields have length limitations and if you overwrite them, the extra chars will be removed. By default this setting is False. Set it to True if you want truncation to raise an exception.

Application Class

The CRM.Application class implements a Singleton pattern that hold all global defined application settings and is used for easy access to these settings. Once the main CRM.Application object is initialized, you can refer to this instance by writing: CRM.Application.instance().

Table below lists the CRM.Application properties.

Property Type Description
config Config Access to the CRM.Config object passed in CRM.Application.Initialize method.
CmtDateFormat String Global RangerMSP date format (as dd/mm/yyyy or mm/dd/yyyy). You'll need to refer to this setting if you are directly manipulating DateTime field (using SetFieldValue method).
CmtDateSeparator String Separator between the date ranges, usually '/', '-' or '.'.
CmtTimeFormat String Global RangerMSP time format.
CmtIsTimeFormatAMPMInUse Boolean 12 hour or 24 hour time format.

Table below list the CRM.Application methods.

Access modifier Method Arguments Return value Description
Public Shared Function instance () Application Method that returns the singleton object. Use it to access all CRM.Application properties/methods.
Public Shared Sub Initialize (ByVal c As Config) Method that initializes the internal RangerMSP API DLLs. Must be the first call before using any other RangerMSP library calls.
Public Shared Sub Terminate () Terminates all RangerMSP internal resources. You should call this method before exit from your application.

CrmField Class

The CRM.CrmField class holds the basic attributes for each database field. For each of the classes that represent RangerMSP objects (Account, Ticket, etc.) there is a preinitialized set of shared CRM.CrmField objects that correspond to the properties defined for the class. For example, the CRM.Account class has a property FileAs (CRM.Account.FileAs). To this property corresponds one shared object instance of the CRM.CrmField class accessible through CRM.Account.Fields.FileAs. To the property LastName (CRM.Account.LastName), corresponds the shared object CRM.Account.Fields.LastName of type CRM.CrmField. And so on, for each property in each class.

Below is a table that lists the properties available in the CRM.CrmField class.

Property Type Description
Key String The internal database field key (as FLDCRDFULLNAME or FLDCRDLASTNAME, etc.)
Type String Internal database field type (as CHAR, MEMO, DOUBLE, TIMESTAMP, etc.)
Size Integer Maximum allowed length for the field data (applies to CHAR Type).
Label String Label for the field
Hint String
Name String
DefaultValue String Default value for the field
DisplaySymbol String For fields that represent currency value this can be $ (for dollar), or for percentage values this can be %

We demonstrate the above in the following sample:

'charge is of type CRM.Charge and is previously initialized
Console.Out.Write(charge.AdjustAmount.ToString() + CRM.Charge.Fields.AdjustAmount.DisplaySymbol)

ObjectQuery Class

CRM.ObjectQuery is a generics class that can operate with any of the CRM.Object derived classes. It is used to query for objects of certain type (Account, Ticket, etc.). For example, the following code snippet searches for all tickets of an account updated since certain date:

Dim ticketSearch As New CRM.ObjectQuery(Of CRM.Ticket)
'account is previously initialized
ticketSearch.AddCriteria(CRM.Ticket.Fields.AccountREC_ID, CRM.OperatorEnum.opEqual, account.AccountREC_ID)
ticketSearch.AddCriteria(CRM.Ticket.Fields.UpdateDate, CRM.OperatorEnum.opGreaterThanOrEqual, DateTime.Parse("01 Jan 2011"))
Dim tickets As List(Of CRM.Ticket) = ticketSearch.FetchObjects()
'tickets now contains all CRM.Ticket objects that satisfy the above criteria.

By default, CRM.ObjectQuery.AddCriteria method uses the logical AND operator to link the conditions. Thus, in case more than one condition are added, all have to be satisfied in order for an object to get into the search results.

In case we want to search for objects and it is enough to satisfy any of the criteria, we can use the OR operator, as in the example below:

Dim accountSearch As New CRM.ObjectQuery(Of CRM.Account)(CRM.LinkEnum.linkOR)

accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, "New York")
accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, "Chicago")
Dim accounts As List(Of CRM.Account) = accountSearch.FetchObjects()
'accounts now contains all CRM.Account objects that satisfy any of the above criteria.

If our search returns lots of objects, it may take some time to get the results back. If not all of the object's fields are need for the given task, we can pass a comma separated string with the field names to the CRM.ObjectQuery.FetchObjects and the objects in the results will have only those fields populated.

Dim accountSearch As New CRM.ObjectQuery(Of CRM.Account)(CRM.LinkEnum.linkOR)

accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, "New York")
accountSearch.AddCriteria(CRM.Account.Fields.City, CRM.OperatorEnum.opEqual, "Chicago")
Dim accounts As List(Of CRM.Account) = accountSearch.FetchObjects(CRM.Account.Fields.AccountREC_ID.Key & "," & CRM.Account.Fields.City.Key)
'CRM.Account objects in the accounts list now contain only the AccountREC_ID and City fields.

The table below explains the important methods of the CRM.ObjectQuery class:

Access modifier Method Arguments Return value Description
Public Sub AddCriteria (ByVal sField As String, ByVal opEnum As OperatorEnum, ByVal sValue As String) Adds one criteria to the initialized CRM.ObjectQuery object instance.

First parameter is the internal field name (column API Field name in the Object derived classes tables), second parameter is the criteria operator (see the table below) and third parameter is the value to search for. This variation of the AddCriteria method should be used only when searching in a field whose name is not included in the predefined fields.

Public Sub AddCriteria (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal sValue As String) Adds one criteria to the initialized CRM.ObjectQuery object instance.

First parameter is one of the CRM.CrmField preinitialized objects included in Fields class in each of the CRM.Object derived classes, second parameter is the criteria operator (see the table below) and third parameter is the value (System.String) to search for. This variation (or the one variations with the System.DateTime or System.Double as third parameter) of the AddCriteria method is the preferred way of adding criteria, unless there is no preinitialized CRM.CrmField object for the field.

Public Sub AddCriteria (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal dtValue As DateTime) Adds one criteria to the initialized CRM.ObjectQuery object instance.

First parameter is one of the CRM.CrmField preinitialized objects included in Fields class in each of the CRM.Object derived classes, second parameter is the criteria operator (see the table below) and third parameter is the value (System.DateTime) to search for. Use this variation to search in fields that are of DateTime type.

Public Sub AddCriteria (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal nValue As Integer) Adds one criteria to the initialized CRM.ObjectQuery object instance.

First parameter is one of the CRM.CrmField preinitialized objects included in Fields class in each of the CRM.Object derived classes, second parameter is the criteria operator (see the table below) and third parameter is the value (System.Integer) to search for. Use this variation to search in fields that are of Integer type.

Public Sub AddCriteria (ByVal field As CrmField, ByVal opEnum As OperatorEnum, ByVal nValue As Double) Adds one criteria to the initialized CRM.ObjectQuery object instance.

First parameter is one of the CRM.CrmField preinitialized objects included in Fields class in each of the CRM.Object derived classes, second parameter is the criteria operator (see the table below) and third parameter is the value (System.Double) to search for. Use this variation to search in fields that are of Double type.

Public Sub AddSortExpression (ByVal sField As String, ByVal sortEnum As SortDirectionEnum) Adds a sort expression to the initialized CRM.ObjectQuery object instance.

First parameter is the internal field name (column API Field name in the Object derived classes tables), second parameter is CRM.SortDirectionEnum (sortASC or sortDESC).

Public Sub AddSortExpression (ByVal field As CrmField, ByVal sortEnum As SortDirectionEnum) Adds a sort expression to the initialized CRM.ObjectQuery object instance.

First parameter is one of the CRM.CrmField preinitialized objects included in Fields class in each of the CRM.Object derived classes, second parameter is CRM.SortDirectionEnum (sortASC or sortDESC).

Public Function FetchObjects () As List(Of T) Executes the constructed query and returns a list of objects (of type T where T is any of the CRM.Object derived classes) that satisfies the criteria.

Below is the table with the available operators (CRM.OperatorEnum) used in the AddCriteria methods.

Enum value Description
CRM.OperatorEnum.opEqual Searches for objects using the exact match (equals) operator
CRM.OperatorEnum.opGreaterThan Searches for objects whose value is greater than the value passed in the third parameter in AddCriteria method.
CRM.OperatorEnum.opGreaterThanOrEqual Searches for objects whose value is greater or equal than the value passed in the third parameter in AddCriteria method.
CRM.OperatorEnum.opLessThan Searches for objects whose value is less than the value passed in the third parameter in AddCriteria method.
CRM.OperatorEnum.opLessThanOrEqual Searches for objects whose value is less than or equal the value passed in the third parameter in AddCriteria method.
CRM.OperatorEnum.opLike Combined with % (percent sign) in the value passed in the third parameter in AddCriteria method can be used for search with broader match.
CRM.OperatorEnum.opNot Searches for objects whose value differs from the one passed in the third parameter in AddCriteria method.
CRM.OperatorEnum.opNotLike

Field length limitations

Most of the database fields (analogous the properties mapped to these fields) have limits on data length that can be accepted. If more than the allowed length is assigned to a field, data is truncated to the length the field is capable of holding and the rest is discarded. Depending on the CRM.Config.RaiseExceptionIfDatabaseFieldTruncated setting (True/False), the operation could raise an exception alerting you that not all of the data was accepted. By default this setting is off (False) resulting in silent truncation of the extra data. Set the CRM.Config.RaiseExceptionIfDatabaseFieldTruncated to True if this behavior is not acceptable.

Below is an example of how to switch this setting ON:

Dim config As New CRM.Config
config.AppName = "VB.NET Demo"
config.DllFolder = "C:\RangerMSP\ThirdParty\UserDev"
config.DbFolder = "C:\RangerMSP\db"
config.RaiseExceptionIfDatabaseFieldTruncated = True'the setting is ON now

'Initialize the CRM.Application
CRM.Application.Initialize(config)

Dim account As New CRM.Account
account.FileAs = "ACME Company"
account.Dear = "Mr."
account.Contact = "John Doe"
'the following line of code will throw an exception because we try to assign more than 40 chars to AddressLine1
account.AddressLine1 = "More than forty characters of the main address line"'Exception is thrown here
account.Save()

See Also