# Add-BomWindowEntity Creates and adds a new entity to the {ref}`BOM Tab `. ## Syntax ```{code-block} powershell :linenos: true Add-BomWindowEntity [[-Type] ] [[-Properties] ] [[-Parent] ] [] ``` ## Parameters | Type | Name | Description | Optional | |---------------------------------------------------------------------------------------------------------------------------------------------|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------| | [BomRow](/code_reference/commandlets/show-bomwindow/objects/bomrow) / [Material](/code_reference/commandlets/show-bomwindow/objects/item) | Type | Specifies whether adding a new [BomRow](/code_reference/commandlets/show-bomwindow/objects/bomrow) or an `Material (Item) ` | no | | PsObject | Parent | For `BomRow’s ` it’s important to specify the parent BOM, where the new row will be added to | yes (not when *Type* is ‘BomRow’) | | Hashtable / PsObject | Properties | The properties for the entity being created | yes | ## Return type [BomRow](/code_reference/commandlets/show-bomwindow/objects/bomrow) **/** [Item](/code_reference/commandlets/show-bomwindow/objects/item) ← on success\ **empty** ← on failure. Exception/ErrorMessage can be accessed using [\$Error](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-5.1#error). ## Remarks The Cmdlet's purpose is to add a new [BomRow](/code_reference/commandlets/show-bomwindow/objects/bomrow) or [Material (Item)](/code_reference/commandlets/show-bomwindow/objects/item) to the [BOM Window](/bom_window).\ The entity's default [State](/bom_window/status) is "*Unknown*". **BomRow:**\ In general two categories of *Properties* can be provided for all newly created BomRows: > - BOM properties are properties prefixed with Bom (e.g. `@{'Bom_Number'= ..., 'Bom_Quantity'= ..., 'Bom_PositionNumber'= ...}`). They are displayed only in the BOM-Tab without the prefix. > - Entity properties are all other properties (e.g. `@{'Number'= ...}`). They are available in the BOM-Tab as well. Custom {ref}`BOM properties ` (e.g. `@{'Bom_Unit'= … ;'Bom_ItemQuantity'= …}`) and {ref}`Entity properties ` (e.g. `@{'Description'= … ; 'SomEntityProperty'= …}`) can be passed and later {ref}`displayed as columns ` in the BOM Window. **Material:**\ It is possible to create the new Material directly with *Properties*. - The name for the new [Item](/code_reference/commandlets/show-bomwindow/objects/item) can be specified as `@{'Number'= ...}`. - Other {ref}`custom properties ` can be specified like `@{'Description'= … ; '_Title(Item,CO)'= …}`. A newly added [Material](/code_reference/commandlets/show-bomwindow/objects/item) has no associated BomRow. ## Examples **Adding a new material in the BOM Window:** ```{code-block} powershell :linenos: true $newMaterial = Add-BomWindowEntity -Type Material -Properties @{'Number'='100001'} ``` **Adding a new BomRow to a BOM in the BOM Window:** ```{code-block} powershell :linenos: true $newBomRow = Add-BomWindowEntity -Type BomRow -Parent $bom -Properties @{'Bom_Number'='PAD LOCK';'Bom_Quantity'= 23.4;'Bom_PositionNumber'=6} ``` **Adding BomRows with information from the ERP as BOM properties**: ```{code-block} powershell :linenos: true $erpBomRow = Get-ERPObject -EntitySet "BomItems" -Keys @{ "ChildNumber"="IWillBeDeleted";"ParentNumber"="CheckBoms";"Position"=1 } $erpBomProperties = @{} foreach ($property in $erpBomRow._Keys.PsObject.Properties) { #Adding _Keys with "Bom_" prefix to pass them as Bom properties $erpBomProperties["Bom_"+$property.Name] = $property.Value } foreach ($property in $erpBomRow._Properties.PsObject.Properties) { #Adding _Properties with "Bom_" prefix to pass them as Bom properties $erpBomProperties["Bom_"+$property.Name] = $property.Value } Add-BomWindowEntity -Type BomRow -Parent $bom -Properties $erpBomProperties <# Bom_Number : Bom_PositionNumber : 1 Bom_Quantity : 1 Bom_ChildNumber : IWillBeDeleted Bom_ParentNumber : CheckBoms _Status : Unknown _StatusDetails : #> ``` **Adding new BomRows that exists in the ERP BOM but not in the Vault BOM and mark them with Status 'Remove':** ```{code-block} powershell :linenos: true functionCheck-Boms($boms) { foreach($vaultBom in $boms) { $erpBom = Get-ERPObject -EntitySet "Boms" -Keys @{ "ParentNumber"= $vaultBom.Bom_Number } -Expand "Children" foreach($erpBomRow in $erpBom.Children) { $vaultBomRow = $vaultBom.Children | Where-Object { $_.Bom_Number -eq $erpBomRow.ChildNumber -and $_.Bom_PositionNumber -eq $erpBomRow.Position } | select -First 1 if($vaultBomRow -eq $null) { $erpBomRow_to_remove = Add-BomWindowEntity -Type BomRow -Parent $vaultBom $erpBomRow_to_remove | Update-BomWindowEntity -Status 'Remove' -StatusDetails 'Row will be deleted in ERP.' } } } } ```