SAP Business One Integration with Service Management System

Jan 15
21:52

2007

Andrew Karasev

Andrew Karasev

  • Share this article on Facebook
  • Share this article on Twitter
  • Share this article on Linkedin

In this small article we will give you SAP BO integration example with C# code. Service Management System uses Microsoft Dynamics CRM 3.0 Case object to store service hours

mediaimage

Integration pulls Customer Number,SAP Business One Integration with Service Management System Articles 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.  In our opinion, if you already invested into eCommerce website and if it is already in production, you should probably consider integrate this legacy e-commerce, rather than redeploy brand new SAP B1 eCommerce solution, this is why such small integrations, as below – are feasible.

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.

If you are looking to integrate your legacy MRP application with SAP BO in different module, Manufacturing/production, for example – SAP Business One SDK can help you to develop similar ongoing integration – it allows you to address virtually all SAP B1 objects

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;

                       

                        description="";

                        itemnumber="";

                        accountNumber="";

                                               

                        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

                        bTime=(double)billableTime;

                        uPrice=(double)unitPrice;

                        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 );

                        }

                  }

            }  

      }  

}