Update-ERPObject

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

Syntax

Update-ERPObject [[-EntitySet] <String>] [[-Keys] <Object>] [[-Properties] <Object>] [<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

Hashtable / PSObject

Keys

The reference properties for the updating item

no

Hashtable / PSObject

Properties

The properties which should be changed

no

Return type

Entity ← on success
empty ← 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 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

Examples

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"}

Error handling, analyze the WebRequestException why the entity could not be updated, by using $Error

Connect-Erp -Service "https://services.odata.org/V3/OData/OData.svc"
$entity = Update-ERPObject -EntitySet "Persons" -Keys @{"ID"=1} -Properties @{"Name"="Sepp Meißnor"}

if(-not $entity){
        $Error[0].Exception.StatusCode #403
        $Error[0].Exception.Message #"You are connected to a read-only data session. Update operations are not permitted for your session"
}