Automate SAP Business One Integration Tasks from PowerShell
The CData ADO.NET Provider for SAP Business One is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SAP Business One.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for SAP Business One; this tutorial shows how to use the Provider to create, retrieve, update, and delete SAP Business One data.
Once you have acquired the necessary connection properties, accessing SAP Business One data in PowerShell can be enabled in three steps.
To authenticate to SAP Business One you must provide the Userand Passwordproperties.
To connect to data, specify Url. This is your SAP Business One Service Layer root URL.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP Business One\lib\System.Data.CData.SAPBusinessOne.dll") -
Connect to SAP Business One:
$conn= New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneConnection("Url=http://localhost:50000/b1s/v1;User=username;Password=password;CompanyDB=dbname;InitiateOAuth=GETANDREFRESH;") $conn.Open() -
Instantiate the SAPBusinessOneDataAdapter, execute an SQL query, and output the results:
$sql="SELECT DocEntry, DocType from Orders" $da= New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.docentry $_.doctype }
Update SAP Business One Data
$cmd = New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneCommand("UPDATE Orders SET DocType='dDocument_Items' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert SAP Business One Data
$cmd = New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneCommand("INSERT INTO Orders (DocType) VALUES (@myDocType)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneParameter("@myDocType","dDocument_Items")))
$cmd.ExecuteNonQuery()
Delete SAP Business One Data
$cmd = New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneCommand("DELETE FROM Orders WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPBusinessOne.SAPBusinessOneParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject