Overview
Coresuite Service allows running scheduled rules in an SAP Business One database independent of the SAP Business One client.
Coresuite Service is conceptually similar to Coresuite Customize and allows code written in C#. The difference between Coresuite Service and Coresuite Customize is mainly that Coresuite Service rules are executed based on a time schedule whereas Coresuite Customize rules are triggered by events in the SAP Business One user interface.
System Requirements
Please check our general System Requirements to see which SAP Business One Versions and Patchlevels are officially supported.
Prerequisites
Coresuite Service is dependent on Coresuite being installed. This is because Coresuite Service uses the Coresuite licensing framework.
Limitations
Coresuite Service rules can use the SAP DI API to add, update and delete objects. The UI API cannot be used because the Coresuite Service process is external to the SAP Business One application. This also applies to the SwissAddonFramework which is accessible from Coresuite Service.
Licensing
A license will need to be installed in Coresuite to be able to use Coresuite Service. This license does not need to be assigned to a specific user.
Installation
Before installing Coresuite Service any previous version must be uninstalled first. Please consult the Uninstallation chapter in the end for more information.
Run the installer, “CoresuiteServiceSetup.msi” and follow the steps in the Wizard. The default choices can be accepted.
Configuration
Coresuite Service Setup creates a file, %ProgramData%\coresystems\Coresuite Service\ CoresuiteServiceConfig.xml. %ProgramData% is usually C:\ProgramData.
Open this file in a text editor and set the configuration values for your system.
Each database needs its own <config> section. If there is only one database using the service, remove the second <config> section. Add additional <config> sections for each database you want to use with Coresuite Service.
The value “systemnumber” is the System Number in SAP (Help > About SAP Business One).
Starting the service
In the Windows Services view, right-click Coresuite Service and select “Start”.
Using Coresuite Service
Coresuite Service installs a shortcut to the Customize Service on the desktop. This is called “Coresuite Customize”.
If more than one database has been defined in the configuration, a dialogue box will pop up, prompting the user to select which database to work with.
Main form, listing all rules:
Creating rules
Click Add Row. The code editor/scheduler will open:
Configure the rule by writing code and setting up a schedule. Click “Save” to save the rule.
Troubleshooting
Coresuite Service creates a table in each configured company database called @COR_SVC_LOG. This is the default logging mechanism in Coresuite Service.
When the database is not available for whatever reason, the backup logging mechanism is by writing text files to %ProgramData%\coresystems\Coresuite Service\Debug Logs.
Please consult these logs and provide the output when contacting support.
Uninstallation
Coresuite Service is distributed as a Microsoft Installer package (msi file). That makes it possible to uninstall the service from Add/Remove Programs in the Control Panel or by double clicking the msi file and selecting the “Remove” option.
Note: Before uninstalling the service, it must manually be stopped in the Windows Services view or command line: net stop coresuiteservice
Additional notes
Accessing the SAP DI API
To get a connection to the SAP Business One DI (SAPbobsCOM.Company), the following pattern is strongly recommended:
using (CoresuiteService.Common.API.SAPConnection sap = CoresuiteService.Common.API.SAPConnection.CreateConnection())
{
// Do stuff
}
The SAPConnection object contains a method, GetB1Connector() that returns a SwissAddonFramework.B1Connector. This gives access to the DI API.
Executing a Master Data Management rule
The following code can be used to trigger a Master Data Management rule:
CoresuiteService.Common.API.MasterDataManagement.ExecuteRule("RuleNameId");
Log a message to the debug table
// Log an info message
CoresuiteService.Common.API.DebugLog.Info("DatabaseName”, "This is the message");
// Log an error message
CoresuiteService.Common.API.DebugLog.Error("DatabaseName”, "This is the message ");
Running SQL queries
Warning: It is strongly discouraged to use the framework object B1Connector described in the section “Accessing the SAP DI API” to run database queries. The reason is that the connection string is initialized with the first company defined in the configuration file. Using this object could, therefore, lead to connecting to/querying the wrong database if there are multiple configurations present.
The following describes best practices in querying a database.
The class SqlQuery in the CoresuiteService.Common.API namespace is designed to execute queries in any database. It contains several useful methods:
object ExecuteScalar(string query)
DbDataReader ExecuteReader(string query)
DataTable GetDataTable(string query)
Pass in the database name to the object’s constructor, and all queries will operate on the database according to the matching entry in the configuration file.
Example
string query = "SELECT CardCode FROM OCRD";
var sql = new CoresuiteService.Common.API.SqlQuery("companyDatabase");
using (System.Data.Common.DbDataReader rdr = sql.ExecuteReader(query))
{
while (rdr.Read())
{
string cardCode = (string)rdr["CardCode"];
// Do stuff
}
}
Comments
Article is closed for comments.