powergate:code_reference:commandlets:update-erpobject

Update-ERPObject

Cmdlet to update an existing entity in the ERP-System.

Update-ERPObject [[-EntitySet] <String>] [[-Keys] <Object>] [[-Properties] <Object>] [<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 updating itemno
Hashtable / PsObject Properties The properties which should be changedno

Entity ← on success
empty ← on failure

This commandlet is used to update an existing entity in ERP.
Per default it uses a HTTP MERGE request.

Method: PUT

When using PUT as PreferredUpdateMethod please note that you have to pass all properties, otherwise it will replace/reset the properties which where not passed.
For more information see: 2.6 Updating Entries

In the following examples we are using the default “ERP” plugin from the powerGateServer. Additionally they assume that objects with following entities exist:

  • On Materials: “Number” = “3169”
  • On Descriptions: “Number” = “6931”, “Language” = “EN”

Update type in Material

Connect-Erp -Service "http://localhost:8080/pgs/ERP/MaterialService/"
$entity = Update-ERPObject -EntitySet "Materials" -Keys @{ "Number" = "3169" } -Properties @{ "Type" = "updated Type"}

Update description in MaterialDescription

Connect-Erp -Service "http://localhost:8080/pgs/ERP/MaterialService/"
$entity = Update-ERPObject -EntitySet "MaterialDescriptions"  -Keys @{ "Number" = "6931";"Language" = "EN" } -Properties @{ "Description" = "changed by powerGate"}

In the following example we are using the public OData Services (http://services.odata.org):
Search for Product and update it
Connect-ERP -Service "http://services.odata.org/V3/(S(xnnohcch2jddbn1z1ytpfni2))/OData/OData.svc/"
$product = Get-ERPObject -EntitySet "Products" -Keys @{"ID"=9}
Update-ERPObject -EntitySet "Products" -Keys $product._Keys -Properties @{"Rating"=9;"Price"=1.99}

<#
ID               : 9
Name             : Lemonade
Description      : Classic, refreshing lemonade (Single bottle)
ReleaseDate      : 01.01.1970 00:00:00
DiscontinuedDate :
Rating           : 9
Price            : 1,99
#>

Update description using PUT as PreferredUpdateMethod

Connect-Erp -Service "http://localhost:8080/pgs/ERP/MaterialService/" -OnConnect {
    param($settings)
    $settings.PreferredUpdateMethod = "PUT"
}
$entity = Update-ERPObject -EntitySet "MaterialDescriptions"  -Keys @{ "Number" = "6931";"Language" = "EN" } -Properties @{ "Description" = "change with PUT request"}