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 a single property of an ERP entity
Connect-Erp -Service "http://localhost:8080/pgs/ERP/MaterialService/"
$entity1 = Update-ERPObject -EntitySet "Materials" -Keys @{ "Number" = "3169" } -Properties @{ "Type" = "updated Type"}
$entity2 = Update-ERPObject -EntitySet "MaterialDescriptions" -Keys @{ "Number" = "3169";"Language" = "EN" } `
-Properties @{ "Description" = "changed by powerGate"} # Instead of updating the Description through the Material entity's navigation property, the referenced MaterialDescription entity is updated separately
Use PUT as preferred update method
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"}
In the following examples we are using the public OData Services (http://services.odata.org):
Modify a previously retrieved ERP entity (all properties)
Connect-ERP -Service 'http://services.odata.org/V3/(S(xnnohcch2jddbn1z1ytpfni2))/OData/OData.svc/'
$supplier = Get-ERPObject -EntitySet 'Suppliers' -Keys @{ 'ID'=1 }
$supplier.Name = 'Tokio Traders (Minato Ward)'
$supplier.Address.City = 'Minato-ku' # note: this property of a nested complex type will be updated together with the entity that contains it
$supplier.Address.Country = 'Japan'
Update-ERPObject -EntitySet 'Suppliers' -Keys $supplier._Keys -Properties $supplier._Properties
<#
ID : 1
Name : Tokio Traders (Minato Ward)
Address : @{Street=NE 40th; City=Minato-ku; State=WA; ZipCode=98052; Country=Japan}
Location : Microsoft.Data.Spatial.GeographyPointImplementation
Concurrency : 4
_Keys : @{ID=1}
_Properties : @{Name=Tokio Traders (Minato Ward); Address=@{Street=NE 40th; City=Minato-ku; State=WA; ZipCode=98052; Country=Japan;}; Location=Microsoft.Data.Spatial.GeographyPointImplementation; Concurrency=4}
#>
Error handling, analyze with 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"
}