![]() |
VOOZH | about |
The CData Cmdlets for SuiteCRM 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 SuiteCRM.
The Cmdlets are not only a PowerShell interface to SuiteCRM, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SuiteCRM data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SuiteCRM. To access SuiteCRM data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SuiteCRM.
Once you have acquired the necessary connection properties, accessing SuiteCRM data in PowerShell can be enabled in three steps.
The User and Password properties must be set to valid SuiteCRM user credentials. Additionally, specify the URL to the SuiteCRM application, for example http://suite.crm.com.
Note that retrieving SuiteCRM metadata can be expensive. It is advised that you store the metadata locally as described in the Caching Metadata section of the data provider help documentation.
Install the module:
Install-Module SuiteCRMCmdlets
Connect:
$suitecrm = Connect-SuiteCRM -URL "$URL" -User "$User" -Password "$Password"
Search for and retrieve data:
$industry = "Manufacturing" $accounts = Select-SuiteCRM -Connection $suitecrm -Table "Accounts" -Where "Industry = `'$Industry`'" $accounts
You can also use the Invoke-SuiteCRM cmdlet to execute SQL commands:
$accounts = Invoke-SuiteCRM -Connection $suitecrm -Query 'SELECT * FROM Accounts WHERE Industry = @Industry' -Params @{'@Industry'='Manufacturing'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SuiteCRM\lib\System.Data.CData.SuiteCRM.dll")
Connect to SuiteCRM:
$conn= New-Object System.Data.CData.SuiteCRM.SuiteCRMConnection("URL=http://mySuiteCRM.com;User=myUser;Password=myPassword;")
$conn.Open()
Instantiate the SuiteCRMDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, Industry from Accounts"
$da= New-Object System.Data.CData.SuiteCRM.SuiteCRMDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.name $_.industry
}
Update-SuiteCRM -Connection $SuiteCRM -Columns @('Name','Industry') -Values @('MyName', 'MyIndustry') -Table Accounts -Id "MyId"
$cmd = New-Object System.Data.CData.SuiteCRM.SuiteCRMCommand("UPDATE Accounts SET Industry='Manufacturing' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SuiteCRM.SuiteCRMParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-SuiteCRM -Connection $SuiteCRM -Table Accounts -Columns @("Name", "Industry") -Values @("MyName", "MyIndustry")
$cmd = New-Object System.Data.CData.SuiteCRM.SuiteCRMCommand("INSERT INTO Accounts (Industry) VALUES (@myIndustry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SuiteCRM.SuiteCRMParameter("@myIndustry","Manufacturing")))
$cmd.ExecuteNonQuery()
Remove-SuiteCRM -Connection $SuiteCRM -Table "Accounts" -Id "MyId"
$cmd = New-Object System.Data.CData.SuiteCRM.SuiteCRMCommand("DELETE FROM Accounts WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SuiteCRM.SuiteCRMParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the SuiteCRM Data Provider to get started:
Download NowLearn more:
👁 SuiteCRM IconRapidly create and deploy powerful .NET applications that integrate with SuiteCRM account data including Leads, Contacts, Opportunities, Accounts, and more!