Cmdlets for SAP Fieldglass

Build 24.0.9060

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our SAPFieldglass Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module SAPFieldglassCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module SAPFieldglassCmdlets;

You can then use the Connect-SAPFieldglass cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-SAPFieldglass -EnvironmentURL "https://myinstance.com" -OAuthClientId "clientId" -OAuthClientSecret "clientSecret" -APIKey "xxxxxxxx-xxxx-xxxx-xxxx"

Obtaining Your Credentials

Please contact your SAP Fieldglass representative to obtain an OAuthClientId, OAuthClientSecret, and EnvironmentURL.

Connecting to SAP Fieldglass

To authenticate to production environments, specify the following:

  • APIKey: Your SAP Fieldglass API Key. To obtain this, log in to the SAP Fieldglass Integration Tools and click Create API Application Key.
  • OAuthClientId: The OAuth Client Id that you obtained from your SAP Fieldglass representative.
  • OAuthClientSecret: OAuth Client Secret that you obtained from your SAP Fieldglass representative.
  • EnvironmentURL: The SAP Fieldglass Environment URL that you obtained from your SAP Fieldglass representative.

Retrieving Data

The Select-SAPFieldglass cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-SAPFieldglass -Connection $conn -Table "AuditTrails" -Columns @("Id, Category") -Where "Company='CData'"
The Invoke-SAPFieldglass cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-SAPFieldglass -Connection $conn -Table AuditTrails -Where "Company = 'CData'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myAuditTrailsData.csv -NoTypeInformation

You will notice that we piped the results from Select-SAPFieldglass into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

 
PS C:\> $conn  = Connect-SAPFieldglass -EnvironmentURL "https://myinstance.com" -OAuthClientId "clientId" -OAuthClientSecret "clientSecret" -APIKey "xxxxxxxx-xxxx-xxxx-xxxx"
PS C:\> $row = Select-SAPFieldglass -Connection $conn -Table "AuditTrails" -Columns (Id, Category) -Where "Company = 'CData'" | select -first 1
PS C:\> $row | ConvertTo-Json
{
  "Connection":  {

  },
  "Table":  "AuditTrails",
  "Columns":  [

  ],
  "Id":  "MyId",
  "Category":  "MyCategory"
} 

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060