# Add-ERPObject Cmdlet to create a new entity and transfers it to an ERP-System. ## Syntax ```{code-block} powershell :linenos: true Add-ERPObject [[-EntitySet] ] [[-Properties] ] [] ``` ## 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, ) | 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 () for demonstration purposes: **Create an orange Juice** ```{code-block} powershell :linenos: true 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 } ``` **Create a person with details (deep create)** ```{code-block} powershell :linenos: true Connect-Erp -Service "http://services.odata.org/V4/OData/(S(fa2g1e4kjczcfnog0asxmvhh))/OData.svc" $entity = Add-ERPObject -EntitySet "Products" -Properties @{ "ID" = 3; "Name" = "Augustin Hodorsson"; "PersonDetail" = @{ "PersonID" = 3; "Age" = 23; "Gender" = $true; "Phone" = "(307) 555-4680123" } } ``` **Create a Product entity using** [New-ErpObject]() ```{code-block} powershell :linenos: true Connect-Erp -Service "http://services.odata.org/V4/OData/(S(fa2g1e4kjczcfnog0asxmvhh))/OData.svc" $product = New-ERPObject -EntityType 'Product'-Properties @{"ID"=11;"Name"="Forst beer"} Add-ERPObject -EntitySet "Products" -Properties $product <# ID : 11 Name : Forst beer Description : ReleaseDate : 01.01.0001 00:00:00 +00:00 DiscontinuedDate : Rating : 0 Price : 0 #> ``` **Error handling, analyze the** [AggregateException]() **why the entity could not be created due to several errors, by using \$Error** ```{code-block} powershell :linenos: true 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'. #> } ```