Ready to get started?

Download a free trial of the SAP Fieldglass Data Provider to get started:

 Download Now

Learn more:

SAP Fieldglass Icon SAP Fieldglass ADO.NET Provider

Provides .NET developers with the power to easily connect their Web, Desktop, and Mobile applications to data to SAP Fieldglass Approvals, Audit Trails, Analytics, and more!

Automate SAP Fieldglass Integration Tasks from PowerShell



Are you in search of a quick and easy way to access SAP Fieldglass data from PowerShell? This article demonstrates how to utilize the SAP Fieldglass Cmdlets for tasks like connecting to SAP Fieldglass data, automating operations, downloading data, and more.

The CData Cmdlets for SAP Fieldglass are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to SAP Fieldglass.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to SAP Fieldglass, but also an SQL interface; this tutorial shows how to use both to retrieve SAP Fieldglass data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SAP Fieldglass. To access SAP Fieldglass data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SAP Fieldglass.

Once you have acquired the necessary connection properties, accessing SAP Fieldglass data in PowerShell can be enabled in three steps.

To authenticate, you will need to specify the Username, Password, APIKey, and EnvironmentURL connection properties.

To obtain an APIKey, log in to the SAP API Business Hub and click on Get API Key.

PowerShell

  1. Install the module:

    Install-Module SAPFieldglassCmdlets
  2. Connect:

    $sapfieldglass = Connect-SAPFieldglass -EnvironmentURL "$EnvironmentURL" -Username "$Username" -Password "$Password" -APIKey "$APIKey"
  3. Search for and retrieve data:

    $company = "CData" $audittrails = Select-SAPFieldglass -Connection $sapfieldglass -Table "AuditTrails" -Where "Company = `'$Company`'" $audittrails

    You can also use the Invoke-SAPFieldglass cmdlet to execute SQL commands:

    $audittrails = Invoke-SAPFieldglass -Connection $sapfieldglass -Query 'SELECT * FROM AuditTrails WHERE Company = @Company' -Params @{'@Company'='CData'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP Fieldglass\lib\System.Data.CData.SAPFieldglass.dll")
  2. Connect to SAP Fieldglass:

    $conn= New-Object System.Data.CData.SAPFieldglass.SAPFieldglassConnection("EnvironmentURL='https://myinstance.com';Username=myuser;Password=mypassword;APIKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the SAPFieldglassDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, Category from AuditTrails" $da= New-Object System.Data.CData.SAPFieldglass.SAPFieldglassDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.category }