# Add-BomWindowEntity Creates and adds a new entity to the [BOM Tab](). ## Syntax ```{code-block} powershell :linenos: true Add-BomWindowEntity [[-Type] ] [[-Properties] ] [[-Parent] ] [] ``` ## Parameters | Type | Name | Description | Optional | |---------------------------------------------------------------------------------------------------------------------------------------------|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------| | [BomRow]() / [Material]() | Type | Specifies whether adding a new [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]() **/** [Item]() ← on success\ **empty** ← on failure. Exception/ErrorMessage can be accessed using [\$Error](). ## Remarks The Cmdlet's purpose is to add a new [BomRow]() or [Material (Item)]() to the [BOM Window]().\ The entity's default [State]() 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 [BOM properties]() (e.g. `@{'Bom_Unit'= … ;'Bom_ItemQuantity'= …}`) and [Entity properties]() (e.g. `@{'Description'= … ; 'SomEntityProperty'= …}`) can be passed and later [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]() can be specified as `@{'Number'= ...}`. - Other [custom properties]() can be specified like `@{'Description'= … ; '_Title(Item,CO)'= …}`. A newly added [Material]() 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 function Check-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.' } } } } ```