Get-ERPObjects

Cmdlet to search for specific entities depending on the passed arguments.

Syntax

1
Get-ERPObjects [[-EntitySet] <String>] [[-Top] <int>] [[-OrderBy] <Object>] [[-Filter] <String>] [[-Expand] <String[]>] [[-Select] <String[]>] [<CommonParameters>]

Parameters

Type

Name

Description

Optional

String

EntitySet

The EntitySet name where the item is located.
It is also possible to specify additional namespaces or the whole url (e.g MaterialService/Materials, http://localhost:8080/PGS/ERP/MaterialService/Materials)

no

Integer

Top

The amount of how many items should be shown

yes

String

Filter

Query what should be executed as a filter

yes

String / Hashtable / Hashtable[]

OrderBy

Items getting ordered by passed property name and/or direction

yes

String[]

Expand

Name/s of navigation properties which should be included.
Navigation properties nested inside a complex type property can also be expanded by specifying the full path (e.g. ComplexTypeProperty/NavigationProperty).

yes

String[]

Select

Name/s of any properties which should explicitly be requested and returned

yes

Return type

Entity [] ← on success
empty array ← on failure. Exception/ErrorMessage can be accessed using $Error.
If the cmdlet fails due to error responses returned by the ERP system, the $Error variable provides a WebRequestException.

Remarks

This Cmdlet is used search for specific entities in the ERP system.

The -Filter argument allows you to specify the filter criteria in OData syntax. More informations about the OData Filter syntax can be found here.

The -OrderBy argument can be specified as String, as hashtable or as an array of hashtables.

  • If the argument is specified as String then the entities are orderd ascending by the passed property name.

  • If the argument is specified as hashtable then the entities are orderd by the passed property name and direction (‘Ascending’ or ‘Descending’)

  • If the argument is specified as array of hashtables, the entities can be orderd by multiple properties, in the specified direction (See example below)

The -Select argument lets you receive only those properties which you want to have in the results.

Depending on the entity model in the ERP system, entities may contain multiple hierarchical levels.
Unlike complex type properties, the navigation properties are not returned by default. To include them in the results, explicitly specify them using the -Expand parameter.
Complex type properties themselves cannot be expanded and do not need to be, since they are always returned by default together with the entity’s other properties. However, a complex type property may itself contain a navigation property. In that case, the navigation property can still be expanded by specifying the path through the complex type property (e.g. -Expand "ComplexTypeProperty/NavigationProperty").

Examples

In the following examples we are using public OData Services (http://services.odata.org) for demonstration purposes:

Search for customers from the company ‘Alfreds Futterkiste’:

1
2
Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
$entity = Get-ERPObjects -EntitySet "Customers" -Filter "CompanyName eq 'Alfreds Futterkiste'"

Search for customers with a companyName starting with ‘A’:

1
2
Connect-Erp -Service "http://services.odata.org/V3/Northwind/Northwind.svc/"
Get-ERPObjects -EntitySet "Customers" -Filter "startswith(CompanyName,'A')"

Get all categories from ERP:

1
2
Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
$entity = Get-ERPObjects -EntitySet "Categories"

Get first 3 Products:

1
2
Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
Get-ERPObjects -EntitySet "Products" -Top 3

Get entities ordered by Name:

1
2
Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
Get-ERPObjects -EntitySet "Products" -OrderBy 'Name'

Get entities ordered by the ProductName <Descending>:

1
2
Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
Get-ERPObjects -EntitySet "Products" -OrderBy @{'ProductName'='Descending'}

Get all suppliers ordered by Country <Ascending> and then City <Descending>:

1
2
Connect-Erp -Service 'https://services.odata.org/V4/OData/(S(fa2g1e4kjczcfnog0asxmvhh))/OData.svc/'
Get-ERPObjects -EntitySet 'Suppliers' -OrderBy @('Address/Country', @{'Address/City'='Descending'} ) # note: here we specify the path to the properties of complex types

Get all OrderID’s of the available ‘Orders’:

1
2
Connect-ERP -Service "http://services.odata.org/V4/Northwind/Northwind.svc"
Get-ERPObjects -EntitySet "Orders" -Select "OrderID"

Error handling: Check if an error appeared by using $? and analyze the WebRequestException to understand why the error occurred, by using $Error:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Connect-ERP -Service "https://services.odata.org/V4/Northwind/Northwind.svc/"
$filter = "startswith(CustomerID,1234567)"
$entities = Get-ERPObjects -EntitySet "Invoices" -Filter $filter

if(-not $entities){
if($? -eq $false){
   $Error[0].Exception.StatusCode #400
   $Error[0].Exception.Message
   <#
     No function signature for the function with name 'startswith' matches the specified arguments.
     The function signatures considered are: startswith(Edm.String Nullable=true, Edm.String Nullable=true).
   #>
   $Error[0].Exception.Response.InnerError.StackTrace
   <#
     at Microsoft.OData.Core.UriParser.Parsers.FunctionCallBinder.MatchSignatureToBuiltInFunction(String functionName, SingleValueNode[] argumentNodes, FunctionSignatureWithReturnType[] signatures)
     ...
     at Microsoft.OData.Service.Parsing.RequestExpressionParser.ParseFilter()
   #>
   }
   else{
     Write-Host("No objects found for the `$filter '$filter'!")
   }
}