![]() |
VOOZH | about |
The CData Cmdlets for Sage Cloud Accounting are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Sage Cloud Accounting.
The Cmdlets are not only a PowerShell interface to Sage Cloud Accounting, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Sage Cloud Accounting data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Sage Cloud Accounting. To access Sage Cloud Accounting data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Sage Cloud Accounting.
Once you have acquired the necessary connection properties, accessing Sage Cloud Accounting data in PowerShell can be enabled in three steps.
You can connect to Sage Business Cloud Accounting using the embedded OAuth connectivity. When you connect, the OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.
Install the module:
Install-Module SageBCAccountingCmdlets
Connect:
$sagebcaccounting = Connect-SageBCAccounting -InitiateOAuth "$InitiateOAuth"
Search for and retrieve data:
$sent = "TRUE" $salesinvoices = Select-SageBCAccounting -Connection $sagebcaccounting -Table "SalesInvoices" -Where "sent = `'$sent`'" $salesinvoices
You can also use the Invoke-SageBCAccounting cmdlet to execute SQL commands:
$salesinvoices = Invoke-SageBCAccounting -Connection $sagebcaccounting -Query 'SELECT * FROM SalesInvoices WHERE sent = @sent' -Params @{'@sent'='TRUE'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Sage Cloud Accounting\lib\System.Data.CData.SageBCAccounting.dll")
Connect to Sage Cloud Accounting:
$conn= New-Object System.Data.CData.SageBCAccounting.SageBCAccountingConnection("InitiateOAuth=GETANDREFRESH;")
$conn.Open()
Instantiate the SageBCAccountingDataAdapter, execute an SQL query, and output the results:
$sql="SELECT contact_name, total_amount from SalesInvoices"
$da= New-Object System.Data.CData.SageBCAccounting.SageBCAccountingDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.contact_name $_.total_amount
}
Update-SageBCAccounting -Connection $SageBCAccounting -Columns @('contact_name','total_amount') -Values @('Mycontact_name', 'Mytotal_amount') -Table SalesInvoices -Id "MyId"
$cmd = New-Object System.Data.CData.SageBCAccounting.SageBCAccountingCommand("UPDATE SalesInvoices SET sent='TRUE' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SageBCAccounting.SageBCAccountingParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-SageBCAccounting -Connection $SageBCAccounting -Table SalesInvoices -Columns @("contact_name", "total_amount") -Values @("Mycontact_name", "Mytotal_amount")
$cmd = New-Object System.Data.CData.SageBCAccounting.SageBCAccountingCommand("INSERT INTO SalesInvoices (sent) VALUES (@mysent)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SageBCAccounting.SageBCAccountingParameter("@mysent","TRUE")))
$cmd.ExecuteNonQuery()
Remove-SageBCAccounting -Connection $SageBCAccounting -Table "SalesInvoices" -Id "MyId"
$cmd = New-Object System.Data.CData.SageBCAccounting.SageBCAccountingCommand("DELETE FROM SalesInvoices WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SageBCAccounting.SageBCAccountingParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Sage Cloud Accounting Data Provider to get started:
Download NowLearn more:
👁 Sage Cloud Accounting IconRapidly create and deploy powerful .NET applications that integrate with Sage Cloud Accounting.