powergate:code_reference:commandlets:get-erpobject

Get-ERPObject

Cmdlet to retrieve a specific entity from the ERP-System.

 Get-ERPObject [[-EntitySet] <String>] [[-Keys] <Object>] [[-Expand] <String[]>] [[-Select] <String[]>] [<CommonParameters>]

Type Name Description Optional
String EntitySetThe 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
Hashtable / PsObject KeysThe reference properties for the searching itemno
String[] ExpandThe Navigation property name(s) which should be expandedyes
String[] SelectSpecifiy the properties which should be explicitly requested and returned by the clientyes

Entity ← on success
empty ← on failure

This commandlet is used to retrieve one specific object from ERP.

As default no navigation properties will be returned. In order to retrieve the entity with navigation properties the -Expand argument has to specified with the according property name.

For instance, if you want to receive only the navigation property without the main entity, then the -Select parameter is the one you are looking for. It will return just the navigation properties you have passed by the names for this paramter.
Attention: If you do not expand them, they will be empty. So, you should be use Select in combination with Expand.

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

Get category with Id 1

Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
Get-ERPObject -EntitySet "Categories" -Keys @{ "CategoryID" = 1 }
<#
CategoryID   : 1
CategoryName : Beverages
Description  : Soft drinks, coffees, teas, beers, and ales                              
Picture      : {21, 28, 47, 0...}
#>

Get one customer with orders

Connect-Erp -Service "http://services.odata.org/V4/Northwind/Northwind.svc/"
Get-ERPObject -EntitySet "Customers" -Keys @{ "CustomerID" = "CACTU" } -Expand "Orders"
<#
Orders       : {Cactus Comidas para llevar, Cactus Comidas para llevar, Cactus Comidas para
               llevar, Cactus Comidas para llevar...}
CustomerID   : CACTU
CompanyName  : Cactus Comidas para llevar
ContactName  : Patricio Simpson
ContactTitle : Sales Agent
Address      : Cerrito 333
City         : Buenos Aires
Region       :
PostalCode   : 1010
Country      : Argentina
Phone        : (1) 135-5555
Fax          : (1) 135-4892
#>

Get only the CategoryID from a category.

$result = Connect-ERP -Service "http://services.odata.org/V4/Northwind/Northwind.svc"
Get-ERPObject -EntitySet "Categories" -Keys @{"CategoryID"=1} -Expand "Products" -Select "CategoryID"
<#
CategoryID : 1
#>

Create empty entity with New-ERPObject, set some properties and search the entity in the ERP System

Connect-ERP -Service "http://services.odata.org/V4/Northwind/Northwind.svc"
$product = New-ERPObject -EntitySet "Products"
$product.ID = 8 

Get-ERPObject -EntitySet "Products" -Keys $product._Keys
<#
ID               : 8
Name             : LCD HDTV
Description      : 42 inch 1080p LCD with Built-in Blu-ray Disc Player
ReleaseDate      : 08.05.2008 00:00:00
DiscontinuedDate :
Rating           : 3
Price            : 1088,8
#>