Add-ERPObject

Cmdlet to create a new entity and transfers it to an ERP-System.

Syntax

1
Add-ERPObject [[-EntitySet] <String>] [[-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

Properties

The properties for the entity being created

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 create an entity in the ERP-System.

Examples

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

Creating a Product with simple properties in the ERP system

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Connect-Erp -Service "http://services.odata.org/V4/OData/(S(fa2g1e4kjczcfnog0asxmvhh))/OData.svc"
$entity = Add-ERPObject -EntitySet "Products" -Properties @{
        "ID "= 5;
        "Name" = "Orange Juice";
        "Description" = "The original Orange Juice. Refreshing!";
        "ReleaseDate" = "2006-08-04T00 =00 =00Z";
        "DiscontinuedDate" = $null;
        "Rating" = 3;
        "Price" = 22.8
}

Creating a Person including navigation- and complex type properties

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Connect-Erp -Service "http://services.odata.org/V4/OData/(S(fa2g1e4kjczcfnog0asxmvhh))/OData.svc"
$entity = Add-ERPObject -EntitySet "Persons" -Properties @{
        "ID" = 3;
        "Name" = "Augustin Hodorsson";

        # Navigation property to other entity that has its own keys (deep create):
        "PersonDetail" = @{
                "PersonID" = 3;
                "Age" = 23;
                "Gender" = $true;
                "Phone" = "(307) 555-4680123";

                # Complex Type property:
                "Address" = @{
                        "Street" = "123 Main St";
                        "City" = "Redmond";
                        "State" = "WA";
                        "ZipCode" = "10999";
                        "Country" = "USA"
                }                
        }
}

Creating a entity using New-ErpObject

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$salesOrder = New-ERPObject -EntityType 'SalesOrder'-Properties @{
        'DocNum' = '100100';
        'Description' = 'Forst beer'
        'Characteristics' = @( @{}, @{}) # every entry is a value object (collection of complex types or navigation property entities)
}
$salesOrder.Characteristics[0].Name = 'Color'
$salesOrder.Characteristics[1].Name = 'Length'

Add-ERPObject -EntitySet 'SalesOrders' -Properties $salesOrder

<#
        DocNum : 100100
        Description : Forst beer
        CreationDate : 01.01.0001 00:00:00 +00:00
        DiscontinuedDate :
        Characteristics : {Color, Length}
#>

Error handling, analyze the AggregateException why the entity could not be created due to several errors, by using $Error

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Connect-ERP "https://services.odata.org/V3/(S(fa2g1e4kjczcfnog0asxmvhh))/OData/OData.svc"
$entity = Add-ERPObject -EntitySet "PersonDetails" -Properties @{"Age"=$true;"Gender"="Female"; "Photo"="This is a Photo"}

if(-not $entity){
        $Error[0].Exception #System.AggregateException: "One or more errors occurred."
        $Error[0].Exception.InnerExceptions
        <#
                Following mandatory properties in entity 'PersonDetail' are missing: 'PersonID'.
                Passed value for entity 'PersonDetail' for property with name 'Photo' has a wrong data type 'String', but should be of type 'Stream'.
                Passed value for entity 'PersonDetail' for property with name 'Gender' has a wrong data type 'String', but should be of type 'Boolean'.
        #>
}