SAP Business One Integration with Service Management System


Visitors: 466

In this small article we will give you SAP BO integration example with C# code. Service Management System uses Microsoft CRM Case object to store service hours. Integration pulls Customer Number, Billable Time, Unit Price, Service Description and Item number from various MS CRM 3.0 objects, such as Activity, User Name, Account and sends them into staging table ALBATIMELOG and from there it sends these fields into SAP B1. Integration is implemented as SAP Business One SDK application – please refer to your SAP B1 reseller to help you with your specific integration challenges

This specific case proves you that you can deploy SAP Business One as back end ERP solution for Servicing company: repair and maintenance, contracts, project organization, field service, consulting, auto-repair shops, communication, telephony, utilities maintenance, etc. SAP Business One supports multicurrency, integration to SAP mySAP, SAP all-in-one, R/3, plus we know cases when SAP B1 is integrated with Microsoft ERP systems, such as Microsoft Great Plains Dynamics GP, Oracle eBusiness Suite/Financials – this is especially important for multinational companies, opening manufacturing or distribution facilities in Brazil.

Below is application code, you should create is as C# console application project in MS Visual Studio

using Microsoft. VisualBasic;
using System;
using System. Collections;
using System. Data;
using System. Diagnostics;
using System. Data. SqlClient;

namespace ConsoleApplication2

sealed public class OrderApp


public static DataTable TableLines; // the datasource of the datagrid called DataLines.

public static SAPbobsCOM. Documents oOrder; // Order object

public static SAPbobsCOM. Documents oInvoice; // Invoice Object

public static SAPbobsCOM. Recordset oRecordSet; // A recordset object

public static SAPbobsCOM. Company oCompany; // The company object

// Error handling variables

public static string sErrMsg;

public static int lErrCode;

public static int lRetCode;

static string description, itemnumber, accountNumber;

public static void Main()


int docNumber=0;

OrderApp. oCompany = new SAPbobsCOM. Company();

OrderApp. oCompany. Server = “localhost"; // change to your company server

OrderApp. oCompany. language = SAPbobsCOM. BoSuppLangs. ln_English; // change to your language

OrderApp. oCompany. UseTrusted = true;

OrderApp. oCompany. CompanyDB = “TEST_SAPBO_ALBA_US";

OrderApp. oCompany. UserName = “manager";

OrderApp. oCompany. Password = “manager";

OrderApp. oCompany. Connect();

Console. WriteLine("Company is: “+OrderApp. oCompany. CompanyName);

SqlConnection connection = new SqlConnection();

connection. ConnectionString = “Integrated Security = true;Data Source = CRMSERVER; Initial Catalog = CRMCUSTOMIZATION;";

connection. Open();

SqlCommand command = new SqlCommand();

command. CommandType = System. Data. CommandType. Text;

command. CommandText = “SELECT * FROM ALBATIMELOG";

command. Connection = connection;

SqlDataReader reader = command. ExecuteReader();

while(reader. Read())


decimal billableTime, unitPrice, lineTotal;

double bTime, uPrice;




Console. WriteLine("Record:");

//reading from timelog

accountNumber=reader. GetSqlString(0). ToString();

billableTime=reader. GetSqlDecimal(1). Value;

unitPrice=reader. GetSqlDecimal(2). Value;

lineTotal=reader. GetSqlDecimal(3). Value;

description=reader. GetSqlString(4). ToString();

itemnumber=reader. GetSqlString(5). ToString();

//add fields



Console. WriteLine(billableTime);

Console. WriteLine(billableTime. ToString());

Console. WriteLine(unitPrice. ToString());

Console. WriteLine(lineTotal. ToString());

Console. WriteLine(description. ToString());

Console. WriteLine(itemnumber. ToString ());

Console. WriteLine();

//Adding order

OrderApp. oOrder = ( ( SAPbobsCOM. Documents )( OrderApp. oCompany. GetBusinessObject( SAPbobsCOM. BoObjectTypes. oOrders ) ) );

// set properties of the Order object

OrderApp. oOrder. CardCode = accountNumber;

OrderApp. oOrder. HandWritten = SAPbobsCOM. BoYesNoEnum. tNO;

SAPbobsCOM. Recordset rs = null;

// Create the next Order number

object sSQL = “SELECT TOP 1 DocNum FROM dbo. ORDR ORDER BY DocNum DESC";

rs = ( ( SAPbobsCOM. Recordset )( OrderApp. oCompany. GetBusinessObject( SAPbobsCOM. BoObjectTypes. BoRecordset ) ) );

rs. DoQuery( System. Convert. ToString( sSQL ) );

while ( !( ( rs. EoF ) ) )


docNumber=System. Convert. ToInt32( rs. Fields. Item( 0 ). Value ) + 1;

rs. MoveNext();


// Default Currency

string dfcurrency="";

sSQL = “SELECT MainCurncy FROM dbo. OADM";

rs = ( ( SAPbobsCOM. Recordset )( OrderApp. oCompany. GetBusinessObject( SAPbobsCOM. BoObjectTypes. BoRecordset ) ) );

rs. DoQuery( System. Convert. ToString( sSQL ) );

while ( !( ( rs. EoF ) ) )


dfcurrency= System. Convert. ToString(rs. Fields. Item( 0 ). Value);

rs. MoveNext();


OrderApp. oOrder. DocNum = docNumber;

OrderApp. oOrder. DocDate = System. DateTime. Today;

OrderApp. oOrder. DocDueDate = System. DateTime. Today. AddDays(30);

OrderApp. oOrder. DocCurrency = dfcurrency;

OrderApp. oOrder. Lines. ItemCode = itemnumber;

OrderApp. oOrder. Lines. ItemDescription = description;

OrderApp. oOrder. Lines. Quantity = bTime;

OrderApp. oOrder. Lines. Price = uPrice;

OrderApp. oOrder. Lines. TaxCode = “00";

OrderApp. oOrder. Lines. LineTotal = uPrice*bTime;

//ATTENTION - you should NOT add last row!!!

//OrderApp. oOrder. Lines. Add();

OrderApp. oCompany. GetLastError( out lErrCode, out sErrMsg );

lRetCode = OrderApp. oOrder. Add(); // Try to add the order to the database

if ( lRetCode != 0 )


OrderApp. oCompany. GetLastError( out lErrCode, out sErrMsg );




} }

Andrew Karasev, Alba Spectrum Group. São Paulo - SP - Brazil +55-11-3444-4949, or skype: albaspectrum, US: 1-630-961-5918 or 1-866-528-0577, ,


Article Source:

Rate this Article: 
Alfresco Development & Content Management System Service
Rated 4 / 5
based on 5 votes

Related Articles:

SAP Business One Ecommerce Integration Highlights

by: Andrew Karasev (January 14, 2007) 
(Computers and Technology)

SAP Business One XML Connector: eCommerce and EDI Integration

by: Andrew Karasev (December 20, 2006) 
(Computers and Technology)

SAP Business: One Chicago Market Review, Plus Customization, Integration & ..

by: Andrew Karasev (January 11, 2007) 
(Computers and Technology)

What is SAP? An In Depth Definition of SAP ERP System

by: Maha Singh (July 10, 2008) 
(Computers and Technology/Software)

Integration of SAP Netweaver

by: Ron Victor (January 05, 2007) 
(Computers and Technology)

Microsoft CRM Integration with Microsoft Retail Management System (RMS) - ..

by: Andrew Karasev (May 06, 2005) 
(Computers and Technology/Software)

Microsoft Great Plains: Service Business Customization & Integration Example

by: Andrew Karasev (June 14, 2005) 
(Computers and Technology/Software)

Data Integration – a approach to simplify the business process through ..

by: Denish Parker (May 28, 2010) 
(Computers and Technology/Software)

5 Telephone System Tips to Delivering Maximum Customer Service from Your ..

by: Nicholas Windley (November 08, 2005) 

Alfresco Development & Content Management System Service

by: Smith Thomas (June 23, 2011) 
(Internet and Businesses Online/Web Design)